One-to-one has-a relationships
In VB, a one-to-one has-a relationship between classes refers to a situation where one class contains an instance of another class as a field or property. This relationship represents an association between the two classes, where the first class directly references an instance of the second class. Here’s an example of a one-to-one has-a relationship in VB:
Public Class Car Public Property Engine As Engine ' Other car-related properties and methods End Class Public Class Engine ' Engine-related properties and methods End Class
In the preceding example, we have two classes: Car
and Engine
. The Car
class has a property called Engine
of the Engine
type and represents the car’s engine. This relationship indicates that a car has a single engine.
To use this relationship, you would typically create instances of the classes and set the appropriate values:
...