반응형

.NET/설계 패턴(C#) 25

[설계 패턴 C#] 15. 책임 연쇄 패턴(Chain of Responsibility Pattern)

15. 책임 연쇄 패턴(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.csusing System.Collections.Generic; namespace ChainofResponsibility{ abstract class ChangeHandler { public ChangeHandler Succ..

[설계 패턴 C#]14. 프락스 패턴(Proxy Pattern) - 보호용 프락시

14. 프락스 패턴(Proxy Pattern) - 보호용 프락시"본문 내용"14. 프락시 패턴(Proxy Pattern) – 보호용 프락시14. 보호용 프락시 설계14. 보호용 프락시 구현▶ IView.csnamespace ProtectionProxy{ interface IView { void View(); string Owner { get; } }} ▶ Picture.csusing System;namespace ProtectionProxy{ class Picture:IView { string name; public string Owner { get; private set; } public Picture(string name,string owner) { this.name = name; Owner = ow..

[설계 패턴 C#]13. 프락스 패턴(Proxy Pattern) - 가상 프락시

13. 프락스 패턴(Proxy Pattern) - 가상 프락시 ▶ IConvert.csnamespace VirtualProxy{ interface IConvert { string Image { get; set; } void ClearImage(); string ConvertImage(); }} ▶ ImageConverter.csusing System;using System.Threading;namespace VirtualProxy{ class ImageConverter:IConvert { public string Image { get; set; } public ImageConverter() { Image = string.Empty; } public void ClearImage() { Image = str..

[설계 패턴 C#]12. 프락스 패턴(Proxy Pattern) - 원격지 프락시

12. 프락스 패턴(Proxy Pattern) - 원격지 프락시"본문 내용"은 언제나 휴일 본 사이트에 있습니다.서버 측 코드▶ ITake.csnamespace RemoteClient{ interface ITake //실제 개체인 카메라가 수행할 수 있는 기능 약속 { string TakeAPicture(); void ChangeMode(bool mode); bool GetMode(); } enum MsgId //실제 개체에 내릴 수 있는 명령 종류 { TAKE=1, CHANGE, GET }} ▶ Camera.csusing System;namespace RemoteProxy{ class Camera:ITake { bool mode = false; //true: 수동 모드, false: 자동 모드 publ..

[설계 패턴 C#] 11. 플라이급 패턴(Flyweight Pattern)

11. 플라이급 패턴(Flyweight Pattern)"본문 내용"은 언제나 휴일 본 사이트에 있습니다.▶ Meta.cs using System; namespace Flyweight{ //사진 촬영 조건에 관한 열거형 정의 public enum BodyType { EH_BA, EH_BB, EH_BC }; public enum LensType { EH_L1, EH_L2, EH_L3 }; public enum LightType { LT_CLEAR, LT_CLOUDY, LT_LAMP }; class Meta //사진 파일들이 공유할 수 있는 촬영 조건을 정의한 클래스 { static readonly string[] bodyname = {"EH_BA","EH_BB","EH_BC"}; static readonly..

[설계 패턴 C#] 10. 퍼샤드 패턴

10. 퍼샤드 패턴"본문 내용"은 언제나 휴일 본 사이트에 있습니다.▶ Picture.cs namespace Facade { class Compensator //하위 계층 서비스 { public void Change(Picture picture, int tone, int brightness, int saturation) { picture.Change(tone, brightness, saturation); } } } ▶ PictureManager.cs namespace Facade { class SmartManager // 사용자가 하위 계층의 기능을 쉽게 사용할 수 있게 제공 { Compensator compensator = new Compensator(); //사진을 수정하는 개체 PictureMana..

[설계 패턴 C#] 9. 장식자 패턴

9. 장식자 패턴 "본문 내용"은 언제나 휴일 본 사이트에 있습니다.▶ Picture.cs namespace Decorator { interface IChange { void Change(Picture picture,int tone,int brightness,int saturation); } } ▶ ToneCompensator.cs namespace Decorator { class BrightnessCompensator:IChange { // IChange에서 약속한 사진을 수정하는 메서드 구현 public void Change(Picture picture, int tone, int brightness, int saturation) { picture.ChangeBrightness(brightness); ..

[설계 패턴 C#] 8. 복합체 패턴

8. 복합체 패턴 "본문 내용"은 언제나 휴일 본 사이트에 있습니다.▶ Tree.cs using System; using System.Collections.Generic; namespace Composite { class Category:Tree { List children = new List(); public Category(string name):base(name) { } public override void View() { Console.WriteLine("{0," + Size.ToString() + "}-C", Name); foreach(Tree child in children) { child.View(); } } public override void AddChild(Tree child) //Ca..

[설계 패턴 C#] 7. 가교 패턴

7. 가교 패턴 "본문 내용"은 언제나 휴일 본 사이트에 있습니다. ▶ IImageProcessing.cs namespace Bridge { class VRModule:IImageProcessing { public string ImageProcessing(string subject) //약속한 기능 구현 { return subject.Replace("떨림",""); } } ▶ PCModule.cs using System.Collections.Generic; namespace Bridge { abstract class Lens { const int min_focuslevel=1; const int max_focuslevel=3; public int FocusLevel { get; private set; }..

[설계 패턴 C#] 6. 적응자 패턴

6. 적응자 패턴 "본문 내용"은 언제나 휴일 본 사이트에 있습니다. *적응자 패턴 적용 전▶PImageProcessor.cs namespace BeforeAdapter { class Camera { PImageProcessor pi_processor; public Camera(PImageProcessor pi_processor) { this.pi_processor = pi_processor; } public string TakeAPicture(string subject) { pi_processor.Subject = subject; pi_processor.ImageProcessing(); return pi_processor.Picture; } } } ▶Program.cs namespace Adapter ..

반응형