1
You have LG branded television. in this scheme I can have different types of televisions and different types of electronics (so that the system can grow and I can use it not only for the tracking of electronics, but also for textile and food tracking)
What is the most correct way to describe this situation?
Way 1
// You can be Electronic, or later a new type like Clothes, Food ...
public class Tipo {
public int Id {get;set;}
public string Descricao {get;set;}
}
// It can be the brand of my electronic, or later a type of Clothing or Food
public class Marca {
public int Id {get;set;}
public string Descricao {get;set;}
public Tipo Tipo {get;set;}
}
// Where this item can be a Television, or a Shirt and even a Chocolate.
public class Item {
public int Id {get;set;}
public string Descricao {get;set;}
public Marca Marca {get;set;}
}
That way I can notice I did the OO as general as possible, but at the time of the creation of the item It is possible to notice that products with different brands may have different attributes. for example, an electronic can have the voltage attribute, where clothes and food would not have. leading this argument in question, it is possible to say that the most correct idea would be:
Way 2
// The guys
public abstract class Eletronico {
public int IdTipo {get;set;}
public string DescricaoTipo {get;set;}
}
public abstract class Roupa {
public int IdTipo {get;set;}
public string DescricaoTipo {get;set;}
}
public abstract class Comida {
public int IdTipo {get;set;}
public string DescricaoTipo {get;set;}
}
// Marks where they belong to a type
public abstract class LG : Eletronico {
public int IdMarca {get;set;}
public string DescricaoMarca {get;set;}
}
public abstract class Samsung : Eletronico {
public int IdMarca {get;set;}
public string DescricaoMarca {get;set;}
}
public abstract class Versace : Roupa {
public int IdMarca {get;set;}
public string DescricaoMarca {get;set;}
}
public abstract class Lascote: Roupa {
public int IdMarca {get;set;}
public string DescricaoMarca {get;set;}
}
public abstract class McDonalds: Comida {
public int IdMarca {get;set;}
public string DescricaoMarca {get;set;}
}
public abstract class BurguerKing: Comida {
public int IdMarca {get;set;}
public string DescricaoMarca {get;set;}
}
// And now yes our items
public class TelevisaoLG : LG {
public int Id {get;set;}
public string Descricao {get;set;}
public int Polegadas {get;set;}
public int Voltagem {get;set;}
}
public class TelevisaoSamsung : Samsung {
public int Id {get;set;}
public string Descricao {get;set;}
public int Polegadas {get;set;}
public int Voltagem {get;set;}
public bool Suporte4k {get;set;}
}
public class Camiseta : Lacoste {
public int Id {get;set;}
public string Descricao {get;set;}
public int Tamanho {get;set;}
}
public class LancheWhooper : BurguerKing {
public int Id {get;set;}
public string Descricao {get;set;}
public int Calorias {get;set;}
}
Thus the oo gets longer but this way it is easier to identify a smaller coupling between classes.
My doubts are:
- What is the most correct way to do it? In way 1 or way 2?
- There is a better way, if yes how?
- In way 2, the correct way is to use even the method
abstract
us
types and brands? and it is possible to make a classabstract
implement
another classabstract
? - Taking into account that the Way 2 is the most appropriate and
we have the following types as an example:
Eletronico
,Roupa
,Comida
. then I have a class for each one. Now the system will also working with a new guyAutomobilistico
so that users can use I will have to update my project creating a classAutomobilistico
(Type)? and generate all Tags and Items in a manner manual? Why in the Way 1 the more generic mode facilitates to create only the typeAutomobilistico
in my database and also add tags and items to the database. Like this would stay in the Way 2?
This "way 2" seems totally meaningless to me. This would generate a model that when you need a new brand will need to generate a new class, which is bad, and
– Ricardo Pontual
Besides, your examples are very confused, mixing TV, clothes, food... after all what you want to model? first think of everything your system should have... will have TV? other electronic? write each and its characteristics (name, color, model, etc). Look at all that’s common. If you have at least one property that is common to all, it may be possible to generate a more "generic" class, such as Item, hence inherit it and model the others, but focus only on what you need, otherwise it becomes difficult for you and the reader to help you
– Ricardo Pontual