We define classes how groups of objects than they are grouped for have equallities of comportment and features and of differ structure of data, because they can duplicates and inherit forming the new classes.
For understanding the classes, we consider the need of to create a object CARRO, will list the features of a CARRO :
Name of object: Carro (model)
Features: Cor, marca (attributes)
Now, we see how declare a class in C#:
Class Carro
Public sCor As String
Public sMarca As String
End Class
But a class of will care all details of a car will are more very complex, it will have details of tires, engine, opcionals. For this, there is a inherited and the polymorphism for to easy the creation of new objects. See:
Class Pneu
Public iTamanho As Integer
Public iLargura As Integer
End Class
Class Carro
Inherits Pneu
Public sCor As String
Public sMarca As String
End Class
Class Caminhao
Inherits Pneu
Public sCor As String
Public sMarca As String
End Class
Class Onibus
Inherits Pneu
Public sCor As String
Public sMarca As String
End Class
Font: http://www.csharpbr.com.br/Portal/VisualizarArtigo.aspx?Artigo=64