Need better a understanding on the Observer Pattern
I have home-work I have to submit but have no idea where to start.
Here is what is needed:
Implement the following using both Delegates and Events as well as the Classic approach to implement the observer pattern (you will thus have to create two separate projects and name them accordingly): b) Write the code for a class that subscribes to the event published by the FinancialService class.
c) Write a program which will test the messaging between the classes.
a) Write all the code that is required to allow other classes who are interested in changes in gold price to be notified.
Nothemba Mapela, May 17, 2012
5. Write FinancialService that will create above obejcts 2,3 and 4. add 2,3 to object 4. then set gold price and call 4.Notify(). 6. U can have two/ three methods that effect gold price icrease 4%, decrease 5%, etc.. 7. write a NUNIt that will call FinancialService class and would check if code written in classes 2,3 has been executed. Project 2 will do exactly same, however.there will be a delegate obejct global and each class will implement method as per delegate implementation. using multcast delegates add methods of classes in order. In financial service class, invoke the delegate using event and same things will happen . U would have to read delegate, multicast delegate and events to do this.
May 17, 2012
Hi, For first project u need to: 1. Create a interface IGoldConsumer with method Update 2. Create a class say CommodityFund that will inherit from IGoldConsumer and in update method, allocate funds if price drops beyond say 2% and sells if price goes above 2% (stragegy to invest) 3. Create another class say BuyGiftForWife that will inherit from IGoldConsumer that will order gold for wife if price goes lesser than say 10000 INR. 4. CReate a class called PriceObserver, that will have method Add accepting IGoldConsumer type param and remove having IGoldConsumer type param. Define local variable List and instantiate it in connstructor. in add method add obect to list , in remove method check and remove from list. In Notify method. foreach IGoldConsumer just call IGoldConsumer.Update().
May 17, 2012