Here you do not need a design template. Just a few principles.
The idea is simple:
An object
determined by his behavior
the object changes only the state of itself the object protects its state
public class SecondClass{ public FirstClass First{get;private set;} public ThirdClass Third{get; private set;} public void DoSomething(){ First.Something++; Second.NotifySomethingHasBeenDone(); } }
If the relationship between the second and third classes is not direct, you can use events to notify:
public class SecondClass{ public FirstClass First{get;private set;} public void DoSomething(){ First.Something++; RaiseEvent<SomethingHasBeenDone>(this); } } public class ThirdClass:IHandles<SomethingHasBeenDone>{ public void Handle(SomethingHasBeenDone @event){ MessageBox("First has {0} something".With(@event.First.Something)); } }
Arnis lapsa
source share