|
/// -----------------------------------------------------------------------------
/// Copyright (C) 2009. All rights reserved.
/// <summary>
/// Example with ObserverPattern to foster the low-coupling and synchronize data while using Denormalization to enhance performance
/// </summary>
/// <history>
/// Status Date By Comments
/// ------------------------------------------------------------------------
/// Created 10 Aug 2009 Henry Created
/// ------------------------------------------------------------------------
/// </history>
/// -----------------------------------------------------------------------------
///
using System;
namespace ObserverPattern_Test
{
/// <summary>
/// The 'ConcreteObserver' class
/// </summary>
class CustomerObserver : Observer
{
private string _name;
private OrderController _subject;
// Constructor
public CustomerObserver(OrderController subject, string name)
{
this._subject = subject;
this._name = name;
}
public override void Update()
{
//YOUR CODE GOES HERE: Send a request to database to update total field for Customer table
bool updateResult = true;
if (updateResult) //Updated successfully
{
this.State = ObserverState.UPDATE_SUCCESSFUL;
Console.WriteLine("'Payment Amount' for Customer who places order {0} has been updated successfully too.", _subject.OrderID);
Console.WriteLine();
}
else
this.State = ObserverState.UPDATE_FAILED;
Console.WriteLine("Observer '{0}'s state is '{1}'", _name, this.State);
Console.WriteLine();
}
// Gets or sets subject
public OrderController Subject
{
get { return _subject; }
set { _subject = value; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I love working with Web-based workflow automation systems, ERP systems for SME, Data Visualization and Augmented Intelligence.
I have been working in ASP.NET for more than 12 years. I've also been working on Java and Windows-based apps for more than 5 years. My core competencies include ASP.NET (+net core), MVC, Restful API, Advance JavaScript, JQuery, Bootstrap, SubSonic, Dapper, Entity Framework, Lucne.net, ElasticSearch Ajax... I'm particularly interested in building smart apps with great UI/UX and high earned value.
I love to write elegant code. I am a type of pragmatic personality.
Recently, I've been interested in developing SPA apps using Angular with NodeJS backend. I also love to write the progressive web apps which could be the next big thing for the mobile web.
Feel free to discuss with me at: phamdinhtruong@gmail.com