+ 4
Oop - going deep into inheritance is the best option?
I am writing a program that has a many different users: visitor, member, writer, Editor, Manager, administrator. There are many behavior that they have in common, like writing: all of them can, start from Writer. so I arrange them in father-son relationship. start with complete abstract User class, then class Member and Visitor inherit from that, then writer from member, Editor from writer, manager from Editor and finally Administrator from Manager. is this deep inheritance right? (god damn 512 char limit )
4 odpowiedzi
+ 5
Hmm, if your compiler shows a warning about that, then it isn't safe, I wouldn't go too far if I were you thou
+ 4
well I think it's not just about compiling, what about the right designing and code reusabilty and not repeating codes?
+ 4
good advise krish, but the whole point that I want to use inheritance is I don't want to repeat the code, with interface I should write the whole block again. but for example writer, editor, manager all write in a same way, so why should I write that again?
I heard about strategy pattern that could solve problems like that, is that right?
+ 3
You should create and Interface when doing this project. try overriding methods when dealing wtih inheritance.
an Abstract class will be of help, but since you dealing with so many people, try coding an Interface (IPerson) and then use it as your base.