inheritance

T

Tony Johansson

Hello!

Assume I want to create a system for a shop which sell media products like
books, DV, DVD and games.

I wonder if a good solution would be to create an abstract class called
Product and then have derived classes
like DV, DVD, BOOKS and games .

//Tony
 
M

Morten Wennevik [C# MVP]

Hi Tiny,

This sounds like classic case where an abstract base class would be in
order. You could also throw in interfaces there as well.

public class DVD : Product, IVideo
 
A

Arto Viitanen

Tony said:
Hello!

Assume I want to create a system for a shop which sell media products like
books, DV, DVD and games.

I wonder if a good solution would be to create an abstract class called
Product and then have derived classes
like DV, DVD, BOOKS and games .

Yes, it is common example on inheritance. But, you also sell yellow
products, blue products and red products. Most likely you also sell
cheap products, expensive products and products on sale.

What I am trying to say is, if DV, DVD, Book and Game are only property
and you do not handle them any differently, there is no need for
inheritance. What about a book that comes with DVD (for example a book
for bird watchers, that has small video of each bird), is it a book or
DVD? Is is book or DVD or both (C# does not support multiple inheritance)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top