Next customersShow customersNewHenry Velasquez customersShowAll Wait for user

Next customersshow customersnewhenry velasquez

This preview shows page 40 - 44 out of 137 pages.

customers.Next(); customers.Show(); customers.New("Henry Velasquez"); customers.ShowAll(); // Wait for user Console.Read(); } } // "Abstraction" class CustomersBase { private DataObject dataObject; protected string group; public CustomersBase( string group) { this .group = group; } // Property public DataObject Data { set { dataObject = value ; } get { return dataObject; } } public virtual void Next() { dataObject.NextRecord(); } public virtual void Prior() { dataObject.PriorRecord(); } public virtual void New( string name) { dataObject.NewRecord(name); } public virtual void Delete( string name) { dataObject.DeleteRecord(name); }
Image of page 40
An Introduction to Design Patterns ****** For more informations visit 41 public virtual void Show() { dataObject.ShowRecord(); } public virtual void ShowAll() { Console.WriteLine("Customer Group: " + group); dataObject.ShowAllRecords(); } } // "RefinedAbstraction" class Customers : CustomersBase { // Constructor public Customers( string group) : base (group) { } public override void ShowAll() { // Add separator lines Console.WriteLine(); Console.WriteLine ("------------------------"); base .ShowAll(); Console.WriteLine ("------------------------"); } } // "Implementor" abstract class DataObject { public abstract void NextRecord(); public abstract void PriorRecord(); public abstract void NewRecord( string name); public abstract void DeleteRecord( string name); public abstract void ShowRecord(); public abstract void ShowAllRecords(); } // "ConcreteImplementor" class CustomersData : DataObject { private ArrayList customers = new ArrayList(); private int current = 0; public CustomersData() { // Loaded from a database customers.Add("Jim Jones");
Image of page 41
An Introduction to Design Patterns ****** For more informations visit 42 customers.Add("Samual Jackson"); customers.Add("Allen Good"); customers.Add("Ann Stills"); customers.Add("Lisa Giolani"); } public override void NextRecord() { if (current <= customers.Count - 1) { current++; } } public override void PriorRecord() { if (current > 0) { current--; } } public override void NewRecord( string name) { customers.Add(name); } public override void DeleteRecord( string name) { customers.Remove(name); } public override void ShowRecord() { Console.WriteLine(customers[current]); } public override void ShowAllRecords() { foreach ( string name in customers) { Console.WriteLine(" " + name); } } } } Output Jim Jones Samual Jackson Allen Good ------------------------ Customer Group: Chicago Jim Jones
Image of page 42
An Introduction to Design Patterns ****** For more informations visit 43 Samual Jackson Allen Good Ann Stills Lisa Giolani Henry Velasquez ------------------------ 4.3 Composite Design Pattern 4.3.1 Definition Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. 4.3.2 UML class diagram The classes and/or objects participating in this pattern are: Component (DrawingElement) Declares the interface for objects in the composition. Implements default behavior for the interface common to all classes, as appropriate.
Image of page 43
Image of page 44

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture