Should this be an object?
- From: "MP" <NoSpam@xxxxxxxxxx>
- Date: Thu, 21 Jun 2007 18:09:54 -0500
Hi
Still trying to learn OO philosophy.
In project A I have an object, lets call it cUnit.
At some point cUnit will be asked to display some information about itself
to the user.
It has a property .DisplayObject to do the work of showing the info and a
method .Display to delegate to the object to do the work.
Maybe the data wants to show up in a label, or a textbox or a listbox, or
listview or treeview etc....depending on the object and the point in the
program and the type of data, etc
at this point for cUnit, the DisplayObject is hard coded to be a listbox
'cUnit
Public Property Set DisplayObject(oDisplayObject As ListBox)
Set moDisplayObject = oDisplayObject
End Property
and the .Display method is
Public Sub Display()
moDisplayObject.AddItem Me.DataToShowUser
End Sub
but for other objects they may only need to show their data in a label or
???
so their display method would be
Public Sub Display()
moDisplayObject.Caption = Me.DataToShowUser
End Sub
or if it were a textbox
Public Sub Display()
moDisplayObject.Text = Me.DataToShowUser
End Sub
etc
this seems too tightly coupled to the type of object doing the displaying
I have the thought to create a class cDisplayObject which could be set to
any appropriate type as req'd
Then cUnit.DisplayObject (and any other class that needs a DispObj) becomes
Public Property Set DisplayObject(oDisplayObject As cDisplayObject)
Set moDisplayObject = oDisplayObject
End Property
and all classes that had a .Display method would use
Public Sub Display()
moDisplayObject.Display Me.DataToShowUser
End Sub
then in cDisplayObject
Private moDispObj as Object
Sub Display(val)
'either a selectcase true on TypeOf or If/ElseIf grouping or ???
If TypeOf (moDispObj) Is TextBox Then
moDispObj.Text = cStr(Val)
ElseIf TypeOf (moDispObj) Is Label Then
moDispObj.Caption = CStr(Val)
ElseIf TypeOf (moDispObj) Is ListBox Then
moDispObj.AddItem CStr(Val)
etc, etc
End Sub
does this seem like the right direction to head?
.
- Follow-Ups:
- Re: Should this be an object?
- From: Larry Serflaten
- Re: Should this be an object?
- From: Robert Morley
- Re: Should this be an object?
- Prev by Date: Re: Create PDF from VB without using a Printer
- Next by Date: Writing a 2D numeric array to a file, and general debugging
- Previous by thread: Re: Multiple text selection in Word
- Next by thread: Re: Should this be an object?
- Index(es):
Relevant Pages
|