I have a class called product, my problem is that I handle products in various ways, either through a list of products, the product itself, and inserting a product into the database. Each handles different properties.
For example, displaying the product on a page will consist of name, description, id, price, brand name, category, image but a list of products would just display just name, thumbnail. Each will have its own methods, for example, one would get top 5 products but the other only displays one product.
My question is how would go about creating classes for this, do I create a different class for each product variation, or create a class consisting of every method and properties thus would consist of a very bulky class.
Start with an Abstract class called Product.
Have all of your common traits/properties/common methods of products in this class.
Derive new product types from this abstract class.
make properties/methods in the abstract class virtual, so
deriving product types can exhibit different behavior depending on the product type.
See if you require the derived product types to explicitly exhibit a
specific behavior. declare such methods as abstract in your abstract class. so the derived class is responsible for implementing that behavior.
abstract class product{
//member fields
//methods
}