Coder Social home page Coder Social logo

Comments (7)

kikito avatar kikito commented on August 22, 2024

Hello there,

The documentation that exists is in the Wiki:

https://github.com/kikito/middleclass/wiki

Is this enough for you, or do you need more guidance?

from middleclass.

raffomania avatar raffomania commented on August 22, 2024

Thanks! I found the documentation in the wiki and read it, but didn't find any information on how inheritance works.

from middleclass.

kikito avatar kikito commented on August 22, 2024

I'm afraid I will have to ask you to be more concise. Are you looking for a description of inheritance as a concept in object orientation? Are you asking about the implementation details of that concept in the context of this library? Or is it something else?

from middleclass.

raffomania avatar raffomania commented on August 22, 2024

I'm looking for precise usage instructions on inheritance in middleclass:

  • What is the Syntax for inheritance? From the quick example, my guess would be that
    class('A', B)
    sets up A to be a subclass of B. But it took me a while to find this, maybe it could be explicitly stated somewhere else?
  • How is initialization handled in class hierarchies? Is the constructor of parent classes automatically called?
  • Is there a way to access a classes or an instances parent class/instance? E.g. A.super?

from middleclass.

kikito avatar kikito commented on August 22, 2024

The standard way to do inheritance is class('A', B). In addition to that, you can also do B:subclass('A'). Both expressions will return A (a subclass of B). A.super will return B.

When you call A:new(), only A:initialize() gets called - the constructor of B is not called by default. There is no super, instead you have to use an explicit self:

function A:initialize()
  ...
  B.initialize(self, ...)
  ...
end

The same applies for non-constructor methods - there is no super keyword-like construction, so you must use explicit self calls.

You may find an example of all this in the Quick Example and on the Readme. Do you feel they are not clear enough?

from middleclass.

raffomania avatar raffomania commented on August 22, 2024

Hey,
that's nice! It clarified a lot of things for me. Indeed, I feel that the Wiki should contain a part exactly like your comment above, to explicitly explain how inheritance works.

from middleclass.

kikito avatar kikito commented on August 22, 2024

Added the notes to the Quick intro pages. Closing down this issue.

from middleclass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.