• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Superclassing for two classes

 
Marwan Adel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I have a question about the best practice for modelling this case:

Every A is B but Not every B is A

All methods and attributes in B is in A

These rules can not be changed

So what is the best practice for modelling this case:

Creating super class C which both A & B inherits it with more attributes for A
Create class A to inherits class B
Or should I decorate class B with more attributes from class A ?

What is your suggestion ? Considering that both A & B will be store in same DB table ?
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an example what A and B are?
 
Marwan Adel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my assignment I have a doctor class, This doctor can provide consultation so he can act as a consultant
Where every consultant is a doctor, While not every doctor is a consultant
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marwan Adel wrote:In my assignment I have a doctor class, This doctor can provide consultation so he can act as a consultant
Where every consultant is a doctor, While not every doctor is a consultant


Ah since giving away answer isn't allow for assignment. I shall give you hint, don't think class, the word starts with "i"

 
Marwan Adel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I think I got it.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic