일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 |
- 설계 패턴
- C언어 소스
- 소프트웨어 접근성
- C# 소스 코드
- C언어 표준 라이브러리 함수 가이드
- C언어
- C++
- math.h
- 소스 구현
- 디딤돌 Java 언어 Part1
- 동적 메모리 할당
- 파일 입출력
- XML.NET
- 소프트웨어 설계
- 디딤돌 C++
- java
- gof의 디자인 패턴
- 무료 Java
- 알고리즘
- C#
- 소스 파일
- C언어 표준 라이브러리 함수 사용법 가이드
- String 클래스
- 소스 코드
- Escort GoF의 디자인 패턴
- 클래스 다이어그램
- 디딤돌 C언어
- StringBuffer 클래스
- JAVA 언어
- C언어 소스 코드
- Today
- 11
- Total
- 98,260
프로그램 소스
[설계 패턴 C#] 15. 책임 연쇄 패턴(Chain of Responsibility Pattern) 본문
[설계 패턴 C#] 15. 책임 연쇄 패턴(Chain of Responsibility Pattern)
Only 프로그램 소스 언제나휴일 2016.12.05 13:0615. 책임 연쇄 패턴(Chain of Responsibility Pattern)
"본문 내용"
[Escort GoF의 디자인 패턴]15. 책임 연쇄 패턴(Chain of Responsibility Pattern)
[Escort GoF의 디자인 패턴] 15. 책임 연쇄 패턴(Chain of Responsibility Pattern) 설계
[Escort GoF의 디자인 패턴] 15. 책임 연쇄 패턴(Chain of Responsibility Pattern) 구현
▶ ChangeHandler.cs
using System.Collections.Generic;
namespace ChainofResponsibility
{
abstract class ChangeHandler
{
public ChangeHandler Successor
{
get;
set;
}
readonly int hid;
public ChangeHandler(int hid)
{
this.hid = hid;
Successor = null;
}
public abstract string ChangeRequest(List<int> mode,string picture);
protected bool IncludeMode(List<int> mode)
{
foreach (int m in mode)
{
if (m == hid)
{
return true;
}
}
return false;
}
}
}
▶ GrayChangeHandler.cs
using System.Collections.Generic;
namespace ChainofResponsibility
{
class GrayChangeHandler:ChangeHandler
{
public GrayChangeHandler(int hid):base(hid)
{
}
public override string ChangeRequest(List<int> mode, string picture)
{
if(IncludeMode(mode))
{
picture = picture.Replace("칼라","흑백");
}
if (Successor != null)
{
picture = Successor.ChangeRequest(mode, picture);
}
return picture;
}
}
}
▶ RedEyeChangeHandler.cs
using System.Collections.Generic;
namespace ChainofResponsibility
{
class RedEyeChangeHandler:ChangeHandler
{
public RedEyeChangeHandler(int hid):base(hid)
{
}
public override string ChangeRequest(List<int> mode, string picture)
{
if (IncludeMode(mode))
{
picture = picture.Replace("빨간눈", "정상눈");
}
if (Successor != null)
{
picture = Successor.ChangeRequest(mode, picture);
}
return picture;
}
}
}
▶ SoftChangeHandler.cs
using System.Collections.Generic;
namespace ChainofResponsibility
{
class SoftChangeHanler:ChangeHandler
{
public SoftChangeHanler(int hid)
: base(hid)
{
}
public override string ChangeRequest(List<int> mode, string picture)
{
if (IncludeMode(mode))
{
picture = picture.Replace("날카로운", "부드러운");
}
if (Successor != null)
{
picture = Successor.ChangeRequest(mode, picture);
}
return picture;
}
}
}
▶ UIPart.cs
using System.Collections.Generic;
namespace ChainofResponsibility
{
class UIPart
{
ChangeHandler head = null;
ChangeHandler tail = null;
public void AddChangeHandler(ChangeHandler handler)
{
if(head != null)
{
tail.Successor= handler;
tail = handler;
}
else
{
head = tail = handler;
}
}
public string ChangeRequest(List<int> mode,string subject)
{
if(head!=null)
{
return head.ChangeRequest(mode,subject);
}
return subject;
}
}
}
using System.Collections.Generic;
namespace ChainofResponsibility
{
class Program
{
static void Main(string[] args)
{
string picture = string.Empty;
List<int> mode = new List<int>();
ChangeHandler[] handlers = new ChangeHandler[3];
handlers[0] = new GrayChangeHandler(0);
handlers[1] = new SoftChangeHanler(1);
handlers[2] = new RedEyeChangeHandler(2);
UIPart uipart = new UIPart();
uipart.AddChangeHandler(handlers[0]);
uipart.AddChangeHandler(handlers[1]);
uipart.AddChangeHandler(handlers[2]);
picture = uipart.ChangeRequest(mode,"칼라 빨간눈 날카로운 몸매");
Console.WriteLine(picture);
mode.Add(0);
picture = uipart.ChangeRequest(mode,"칼라 빨간눈 날카로운 몸매");
Console.WriteLine(picture);
mode.Add(2);
picture = uipart.ChangeRequest(mode,"칼라 빨간눈 날카로운 몸매");
Console.WriteLine(picture);
mode.Add(1);
picture = uipart.ChangeRequest(mode,"칼라 빨간눈 날카로운 몸매");
Console.WriteLine(picture);
}
}
}'설계 패턴(C#)' 카테고리의 다른 글
[설계 패턴 C#] 17. 해석자 패턴(Interpreter Pattern) (0) | 2016.12.07 |
---|---|
[설계 패턴 C#] 16. 명령 패턴(Command Pattern) (0) | 2016.12.06 |
[설계 패턴 C#] 15. 책임 연쇄 패턴(Chain of Responsibility Pattern) (0) | 2016.12.05 |
[설계 패턴 C#]14. 프락스 패턴(Proxy Pattern) - 보호용 프락시 (0) | 2016.06.24 |
[설계 패턴 C#]13. 프락스 패턴(Proxy Pattern) - 가상 프락시 (0) | 2016.06.24 |
[설계 패턴 C#]12. 프락스 패턴(Proxy Pattern) - 원격지 프락시 (0) | 2016.06.23 |