Hi guys,
I have 3 classes : 1.Product(Super Class) 2.SmartDevice(Sub Class) 3.Accessories(Sub Class)

so I made 3 tables in database and made productId as a foreign key for smartDevice table and accessories table

so I've had a trouble thinking about what the code of CRUD will be if I used the generalization I mentioned above

Example:
I want to add a function to insert a product into database in the class of product

I Left 2 attachments to explain my condition:

71b1ae6c75814548b76a0cb671b1dd94

233e4d4d451511809150b34805e2be0f

If I understand your question you want to insert a product into the products table and then, depending on whether it is an accessory or a smart device, also insert into the relevant secondary table.
So your secondary, subclass tables will have a productId column that matches the productId in the products table.
Insert a product into the products table and return the inserted productId. Use that id to do the insert into the secondary table. You now have a link between the two.
You can also add a foreign key constraint from accessories/smart devices to products with on delete cascade to keep your table integrity intact.
is that any help?

Thank you alot your answer really helped me alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.