Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Optimizing Performance with Denormalization, Observer Design Pattern and Asynchronous Technique

, 24 Aug 2009
Making use of Denormalization, Observer Design Pattern and Asynchronous technique can enhance performance for any system with massive database.
/// -----------------------------------------------------------------------------
/// 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 SalesPersonObserver : Observer
  {
    private string _name;
    private OrderController _subject;

    // Constructor
    public SalesPersonObserver(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("'Total Sold Amount' for SalesPerson who processed 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pham Dinh Truong
Technical Lead
Vietnam Vietnam
I have been working in ASP.NET for more than 7 years. I've also been working on Java and Windows-based apps for more than 4 years. My core competences include ASP.NET, Design Patterns, SubSonic, Ajax, Asynchronous and Multi-threading. I'm particularly interested in building smart software with great UI/UX and rich User Experience.
 
Recently, I'm interested on developing online advertisements. It's so complicated just like studying a new programming language!
 
Feel free to discuss with me at: phdtruong@yahoo.com.
 
Visit my home:
http://smartwebdevelopment.blogspot.com
https://www.facebook.com/SmartWebDevelopment
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web03 | 2.8.140902.1 | Last Updated 24 Aug 2009
Article Copyright 2009 by Pham Dinh Truong
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid