Dilantha Madhushan
Dilantha Madhushan

Reputation: 1

how to model inheritance in object oriented programming

suppose there is a parent class and 3 child classes.If there's a method which needs to be included in two of the child classes where to place it?

Upvotes: 0

Views: 115

Answers (2)

nIcE cOw
nIcE cOw

Reputation: 24626

I say the structure has to be like this

    Parent
    |    |
Child   ChildTwo
        |       |
ChildTwoFirst   ChildTwoSecond

Here ChildTwo class will have your added method. Hope that might help

Regards

Upvotes: 2

user229044
user229044

Reputation: 239342

In the child classes which need it, either directly or by defining an intermediate super class for the two specific children which inherits from the parent. If the method cannot be invoked on the parent, or on all of its children, it doesn't belong in the parent.

Upvotes: 1

Related Questions