Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear All,

 

 

This is my first post in the forum, though I've posted loads of times in XVBT, so I'll make this a nice meaty one for the experts (I hope).

 

Presently, I have defined a data tree structure to hold diary information. The structure works something like:

 

Event (container)
|
+- Event (container)
|
+- Action (container)
|   |
|   +- Causality
|
+- Causality

 

Basically, each event can contain further events or an action or causality. Actions can only contain causalities.

 

Each object that changes invokes a change event. Each container that changes invokes a change event.

 

My problem is that I don't know how to promote change events up the hierachy :confused:. If anyone could point me in the right direction, I would really appreciate it.

 

 

Many thanks in advance,

Paul.

Posted (edited)

Off the top of my head:

 

Each object could contain a Parent property that gets assigned when you create the object. Raise the Change event to the parent.

 

Am I missing something?

 

Here's some quick code:

 

Public Class BaseObject

   Private _parent As BaseObject
   Private _name As String
   Private _children As New Collection

   Public Property Parent() As BaseObject
       Get
           Return _parent
       End Get
       Set(ByVal Value As BaseObject)
           If _parent Is Nothing Then _parent = New BaseObject
           _parent = Value
       End Set
   End Property

   Public Property Name() As String
       Get
           Return _name
       End Get
       Set(ByVal Value As String)
           _name = Value
       End Set
   End Property

   Public Property Children()
       Get
           Return _children
       End Get
       Set(ByVal Value)

       End Set
   End Property

   Public Sub AddChild(ByVal child As Object)
       child.Parent = Me
       _children.Add(child)
   End Sub
   Public Sub Change()
       Debug.WriteLine("Change handled by BaseObject: " & Name)
   End Sub

End Class

Public Class EventObject
   Inherits BaseObject

   Public Shadows Sub Change()
       Debug.WriteLine("Change event handled by EventObject: " & Name)
       Me.Parent.Change()
   End Sub

End Class

Public Class ActionObject
   Inherits BaseObject

   Public Shadows Sub Change()
       Debug.WriteLine("Change event handled by ActionObject: " & Name)
       Me.Parent.Change()
   End Sub
End Class

Public Class CasualtyObject

   Private _parent As ActionObject
   Private _name As String

   Public Sub New()
       _parent = New ActionObject
   End Sub

   Public Property Parent() As ActionObject
       Get
           Return _parent
       End Get
       Set(ByVal Value As ActionObject)
           _parent = Value
       End Set
   End Property

   Public Property Name() As String
       Get
           Return _name
       End Get
       Set(ByVal Value As String)
           _name = Value
       End Set
   End Property

   Public Sub Change()
       Me.Parent.Change()
   End Sub
End Class

'test bed
       Dim obj As New EventObject
       Dim child As Object
       Dim child2 As Object

       obj.Name = "Parent"

       child = New EventObject
       CType(child, EventObject).Name = "Child 1"

       obj.AddChild(child)

       child = New ActionObject
       CType(child, ActionObject).Name = "Child 2"

       child2 = New CasualtyObject
       CType(child2, CasualtyObject).Name = "Child 3"

       child.AddChild(child2)
       obj.AddChild(child)

       CType(child2, CasualtyObject).Change()

Edited by Machaira
Here's what I'm up to.
Posted

I can see where you're coming from, Machaira, the only problem there is that, if branch C contains D, E and F, then even if one of the nodes fires a Change event, how does B, the parent of C know that the change event has been fired?

 

I suppose one option is to use the idea you have and include a reference to the ultimate parent - this would fire a change. It sounds a little messy, but it might work.

 

Trust me, Machaira - you know more than I at this stage! LOL!

 

 

Paul.

Posted

Machaira,

 

 

I've just read the code you've added there - that does make sense. You've defied a base class that is inherited by each object...

 

I can see that working, after all, it's only the ultimate parent that needs to be referenced for change.

 

I'll give that a go, and see how it works!

 

Please accept my profuse thanks! :)

 

 

Paul.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...