On Fri, Nov 29, 2013 at 3:34 PM, TW <
terry...@googlemail.com> wrote:
> I'm using multi-table inheritance in project and need some help geeting my
> mind around this concept
>
> I have parent class 'test' which is a machine test (members : name, version
> state; methods : add_test, remove_test)
>
> I now create a child class 'result' which inherits from parent class 'test'
> - 'result' is the result of all the scenarios inside the machine test
> (multiple scenarios per machine test)
>
> Child class 'result' will have its own members/methods (members :
> scenario_name, scenario_outsome; methods : add_result, delete_result)
>
> So now I can create an instance of parent 'test' class by calling the child
> class 'result'
> >>>>testme= result.add_test("""args""")
>
> So what is now in the object "testme" that I just created? I cannot
> viasualise what this instance holds and how the parent/child relationship
> works
I'm also having difficulty visualising this, since inheritance is not
about providing a parent/child relationship.
Your models does not seem appropriate for inheritance. Inheritance
provides an "is-a" relationship. "Frog" can extend "Animal" because
Frog is-a Animal, but a "result" is not a "test".
Another way of thinking about inheritance is substitutability. A
derived class should always be usable in place of a base class, so if
you had a function which took a "test" object, could you replace that
instance with it "result" object without any code changes to the
function?
It sounds much more likely that you want to relate these classes
together with object composition, which gives a "has-a" relationship -
"test" has-a "result". You can do object composition using foreign
keys (which is much the same way inheritance is done) but the verbs
and attributes added are different.
It might make your code easier to scan, and get rid of the API where
you create a test by adding it to an existing result(?!)
Cheers
Tom