Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hey Guys,

I have a parent class Fruits and two nested classes like Apple and Orange.This relationship is called inheritance.but can anyone plz tell me if i want to design table structure in the database.what would be that relationship called and how can i design/relate tables from that schema ?


Thanks in Advance.
Posted
Comments
PIEBALDconsult 2-Mar-14 1:22am    
I doubt your example is very good. It is quite likely that you only need one table -- Fruit -- and something to indicate Type -- Apple, Orange, etc.
Or, if Apple and Orange are too dissimilar, then you might have an Apple table and an Orange table.

Read these, hopefully they can give your some ideas:
1. c-oop-abstract-classes-fruit[^]
2. how-do-you-effectively-model-inheritance-in-a-database[^]
 
Share this answer
 
Nested is totally irrelevant to inheritance. To use inheritance, you should derive Apple an Orange from Fruit. (I changed base class name to singular; your use of plural is based on you deep confusion about inheritance and the very role of classes and instances.)

And of course, it's way to early to discuss databases with you. You are just not ready. So far, you have no clue on how OOP works and need to learn it (and, I'm sure, very many basics things) before you get to anything advanced.

—SA
 
Share this answer
 
YOu could give more details for your problem. You can take a table T_FRUIT with a primary key and give the primary key to T_APPLE and T_ORANGE as foreign key.

T_FRUIT
FruitsId
FruitsName
FruitsSize

T_APPLE
AppleId
FruitsId
AppleColor

T_ORANGE
OrangeId
FruitsId
OrangeColor
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900