Re: Should this be an object?
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Jun 2007 20:18:30 -0400
If it were me, I'd leave the controls out of your object altogether.
Normally, the GUI takes care of the GUI and the object takes care of the
object. In other words, something like:
MyControl.Caption = MyObject.DataToShowUser
or
MyListBox.AddItem MyObject.DataToShowUser
Usually, the GUI is aware of what type of control it's using, so why try to
make your objects be aware of it as well? They probably don't need to be.
Rob
"MP" <NoSpam@xxxxxxxxxx> wrote in message
news:eYpNHlFtHHA.4688@xxxxxxxxxxxxxxxxxxxxxxx
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: Steve Gerrard
- Re: Should this be an object?
- References:
- Should this be an object?
- From: MP
- Should this be an object?
- Prev by Date: Writing a 2D numeric array to a file, and general debugging
- Next by Date: Re: Writing a 2D numeric array to a file, and general debugging
- Previous by thread: Should this be an object?
- Next by thread: Re: Should this be an object?
- Index(es):
Relevant Pages
|