I would like to know How inheritance will be used in real world project.
E.g. Consider an example of Bank Account
Approach 1:
When I map these classes with database, using Hibernate using one of the inheritance strategy, e.g. table per sub class, I will end up with three tables. Account, Saving_account and Current_account.
Advantage: I can call operation1() depending on the type of object using
polymorphism.
Disadvantage: more tables and classes.
Approach 2:
I need only 1 table for this approach called Account. And "type" field will identify the type of the account.
Advantage: Only 1 table and class.
Disadvantage: I will lose Object oriented world and every place I have to put the condition as below.
As per theory, approach 1 is correct and best. But currently in my project, approach 2 is used. My project is not banking. I took it as an example for the simplicity. Also approach 1 is good for maintaining large complex projects.
Thanks in advance for your inputs.