Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Business Components

Status
Not open for further replies.

fostom

Programmer
Jul 3, 2002
31
NO
Hi..

Let's say I import a self made business object.

dim myObj as new MyBusinessObject

..in this object I have numerous of functions, and I call them like this:

myObj.function1
myObj.function2
myObj.Car

..but how can I make myObj.Car call for another method, ex color? Like this:

myObj.Car.Color("red")

Anyone know a good tutorial for this. Is it "polymorphic" code that I need?

Regards, Tommy
 
Is car a function or an object. This is example is a little too abstract to really help you out. Post a little more information on what you are really trying to do. I will help.

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Yes, car is a function. Lets say it looks like this.. (this is not my real code, just an example.. I just want the get the understanding) (I am using VS.NET)

namespace myComponent
public class vehicle
public function car()
....
end function

public function color()
....
end function
....
....
end class
end namespace

The class vehicle have a function called car. And when I import the namespace myComponent to another project how can I use the syntax myObj.car.color? Because when I import the namespace myComponent and dim myObj as vehicle, all I get is all the funtions in the class. Like myObj. will show me two functions named car and color in the intelliSense. How do I set up the code so when I type myObj.car. the intelliSence will show me the color function to add?

Do you understand? I am so bad at explaining.. :(

Tommy
 
Well it seems like you are confusing a function with an object. Car should be its own object. You can then have a property that holds your car class.

Public Class Car

Private mMake As String
Private mModel As String
Private mColor As Color

Public Property Make() As String
Get
Return mMake
End Get
Set(ByVal Value As String)
mMake = Value
End Set
End Property

Public Property Model() As String
Get
Return mModel
End Get
Set(ByVal Value As String)
mModel = Value
End Set
End Property

Public Property Color() As Color
Get
Return mColor
End Get
Set(ByVal Value As Color)
Color = mColor
End Set
End Property

End Class


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Here is your object Class
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Class myObject
Private mCar As Car
Public Property Car() As Car
Get
Return mCar
End Get
Set(ByVal Value As Car)
mCar = Value
End Set
End Property
End Class

Then you can use your car object inside your other object if you want or you can pass the object to whatever needs it.

Dim myO as new myObject
Dim myCar as new Car

myCar.Make = "Honda"
myCar.Model = "Civic"
myCar.Color = Color.Blue


myO.Car = myCar


Let me know if you understand what I am explaining here.



DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Ok, so far so good. But how would the Car class look like if I use this statement in the myObject object:

Dim myCar as new Car
myCar.Tires.Dimension("255")

That is actually my main question.. how can I add another "level" to the query?

Level1 = myCar.
Level2 = Tires.
Level3 = Dimension("255")
..and so on..

Level1.Level2.Level3 = myCar.Tires.Dimension("255")

Until now we only have two levels which are e.g. myCar.Color

Do you catch my drift?

Tommy
 
If "Tires" is complex( meaning that it has many properties like Dimention, tirepressure, color, whitewall, thickness etc...) then you would create another object for tires and add it as a property to the car class. Just like You added the car class to the object class.

Class Tires

Public Properties Dimention as String

ETC.....


But if it is not that complex then I would just add it as a property to the car class


Public Property Tire_Dimention as String




DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top