0

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?

1
  • 1
    perhaps what you really have is a grandparent with two children one of which has two grandchildren. Commented Jan 4, 2012 at 15:57

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.