I have the following configuration to create a basic vehicle with an engine.
This is an example of how I instantiate the object.Code:Interface IEngine End Interface Class Vehicle Dim VehicleEngine As IEngine Public Property Engine() As IEngine Get Return VehicleEngine End Get Set(ByVal value As IEngine) VehicleEngine = value End Set End Property Sub New() Me.Engine = New Engine End Sub End Class Class Engine Implements IEngine End Class
This is simple also, but a question starts to come up.Code:Dim Police as New Vehicle
In the above example I destroyed the VehicleEngine object which was created in the constructor when I created the Police object. When this code is complete, the Engine that is destroyed will first be copied into a Garage object. If you are with me so far, I have a quick question. Right now with these examples I am doing the swap manually. Create Object, Copy Object and Destroy Object. Both ways (removing engine and adding engine). Is this the best way to do this, or is there a simpler more efficient way to do the swap.Code:Police.Engine = Nothing
I have a second question. What would be the best way to create an array of Engines in the above code in the vehicle class instead of just the single engine. So assume that the car can have a hundred engines. What would you alter in the code above to be able to get and set a hundred different engines. I am referring to not have to create a hundred properties but to use one to manage a hundred objects. I definitely could use help with that.




Reply With Quote