static void Main(string[] args) { //BuilderExample(); //FactoryExample(); //FactoryMethodExample(); //FactoryMethodExample2(); //ProtoTypeExample(); //SingletonExample(); //AdapterExample();
BridgeExample();
//Console.WriteLine("Hello World!"); Console.ReadKey(); }
static void BridgeExample() { Customers customers = new Customers("Chicago") { DataObject = new CustomersData() };
customers.ShowRecord(); customers.NextRecord(); customers.ShowRecord(); customers.NextRecord(); customers.ShowRecord(); customers.AddRecord("henry velasquez");
customers.ShowAll(); }
main.cs |
using System; using System.Collections.Generic; using System.Text;
namespace DesignPatterns.Structural_Patterns.Bridge { public class Customers : CustomersBase { public Customers(string group) : base(group) {
}
public void ShowAll() { Console.WriteLine(); Console.WriteLine("------------------------"); base.ShowAllRecords(); Console.WriteLine("------------------------"); } } }
Customers.cs |
using System;
namespace DesignPatterns.Structural_Patterns.Bridge { public class CustomersBase : IDataObject { public IDataObject DataObject { get; set; } protected string group;
public CustomersBase(string group) { this.group = group; }
public void NextRecord() { DataObject.NextRecord(); }
public void PriorRecord() { DataObject.PriorRecord(); }
public void AddRecord(string name) { DataObject.AddRecord(name); }
public void RemoveRecord(string name) { DataObject.RemoveRecord(name); }
public void ShowRecord() { DataObject.ShowRecord(); }
public void ShowAllRecords() { Console.WriteLine("Customer Group : {0}", group); DataObject.ShowAllRecords(); } } }
CustomersBase.cs |
using System; using System.Collections.Generic;
namespace DesignPatterns.Structural_Patterns.Bridge { public class CustomersData : IDataObject { private List<string> customers = new List<string>(); private Int32 current = 0;
public CustomersData() { customers.Add("Jim Jones"); customers.Add("Samual Jackson"); customers.Add("Allen Good"); customers.Add("Ann Stills"); customers.Add("Lisa Giolani"); }
public void AddRecord(string customer) { customers.Add(customer); }
public void NextRecord() { if (current <= customers.Count - 1) current++; }
public void PriorRecord() { if (current > 0) current--; }
public void RemoveRecord(string customer) { customers.Remove(customer); }
public void ShowAllRecords() { foreach(string customer in customers) { Console.WriteLine(customer); } }
public void ShowRecord() { Console.WriteLine(customers[current]); } } }
CustomersData.cs |
using System; using System.Collections.Generic; using System.Text;
namespace DesignPatterns.Structural_Patterns.Bridge { public interface IDataObject { void NextRecord(); void PriorRecord(); void AddRecord(string name); void RemoveRecord(string name); void ShowRecord(); void ShowAllRecords(); } }
IDataObject.cs |
참고 사이트
'C# 디자인패턴' 카테고리의 다른 글
11# Decorator패턴 Structural Patterns (0) | 2019.06.03 |
---|---|
10# Composite패턴 Structural Patterns (0) | 2019.06.03 |
08# Adapter 패턴 Structural Patterns (0) | 2019.05.29 |
07# Singleton 패턴(thread safe) Creational Patterns (0) | 2019.05.24 |
06# Prototype 패턴 Creational Patterns (0) | 2019.05.23 |