저는 Eric Gamma가 Deign 패턴에 대해 Reusable Object Oriented Software의 Elements라는 요소를 언급하고 있습니다. 그러나 Facade 패턴의 개념을 이해했지만, 여전히 구현 부분을 구현하는 데 약간의 가난함이 없으므로 책에서 제공된 구현 지점을 이해할 수 없습니다.외관 디자인 패턴 - 구현
아래는이 책에서 언급 된 2 점은 다음과 같습니다
클라이언트 서브 시스템 커플 링을 감소 : 외관 클래스 추상 클래스함으로써.
공용 v/s 개인 서브 시스템 클래스.
사람은 일부 예제 또는 코드 나에게 이것을 설명시겠습니까 내가 가진 : 추상 클래스와
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Facade_CSharp
{
class Program
{
static void Main(string[] args)
{
Facade facade = new Facade();
facade.ProcessA();
facade.ProcessB();
// Wait for user
Console.ReadKey();
}
}
/// <summary>
/// The 'Subsystem ClassA' class
/// </summary>
class SubSystemOne
{
public void MethodOne()
{
Console.WriteLine(" SubSystem One");
}
}
/// <summary>
/// The 'Subsystem ClassB' class
/// </summary>
class SubSystemTwo
{
public void MethodTwo()
{
Console.WriteLine(" SubSystem Two");
}
}
/// <summary>
/// The 'Subsystem ClassC' class
/// </summary>
class SubSystemThree
{
public void MethodThree()
{
Console.WriteLine(" SubSystem Three");
}
}
/// <summary>
/// The 'Subsystem ClassD' class
/// </summary>
class SubSystemFour
{
public void MethodFour()
{
Console.WriteLine(" SubSystem Four");
}
}
/// <summary>
/// The 'Facade' class
/// </summary>
class Facade
{
private SubSystemOne _one;
private SubSystemTwo _two;
private SubSystemThree _three;
private SubSystemFour _four;
public Facade()
{
Console.WriteLine("\nRequests received from Client System and Facade is in execution... ");
_one = new SubSystemOne();
_two = new SubSystemTwo();
_three = new SubSystemThree();
_four = new SubSystemFour();
}
public void ProcessA()
{
Console.WriteLine("\nProcessA of Facade uses the following subsystems to accomplish the task:");
_one.MethodOne();
_two.MethodTwo();
_four.MethodFour();
}
public void ProcessB()
{
Console.WriteLine("\nProcessB of Facade uses the following subsystems to accomplish the task:");
_two.MethodTwo();
_three.MethodThree();
}
}
}
코드 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Facade_abstract
{
class Program
{
static void Main(string[] args)
{
FacadeAbs facade = new FacadeAbs();
facade.ProcessA();
facade.ProcessB();
// Wait for user
Console.ReadKey();
}
}
class SubSystemOne
{
public void MethodOne()
{
Console.WriteLine(" SubSystem One");
}
}
/// <summary>
/// The 'Subsystem ClassB' class
/// </summary>
class SubSystemTwo
{
public void MethodTwo()
{
Console.WriteLine(" SubSystem Two");
}
}
/// <summary>
/// The 'Subsystem ClassC' class
/// </summary>
class SubSystemThree
{
public void MethodThree()
{
Console.WriteLine(" SubSystem Three");
}
}
/// <summary>
/// The 'Subsystem ClassD' class
/// </summary>
class SubSystemFour
{
public void MethodFour()
{
Console.WriteLine(" SubSystem Four");
}
}
/// <summary>
/// The 'Facade' class
/// </summary>
public abstract class Facade
{
//public abstract Facade();
public abstract void ProcessA();
public abstract void ProcessB();
}
public class FacadeAbs : Facade
{
private SubSystemOne _one;
private SubSystemTwo _two;
private SubSystemThree _three;
private SubSystemFour _four;
public FacadeAbs()
{
Console.WriteLine("\nRequests received from Client System and Facade is in execution... ");
_one = new SubSystemOne();
_two = new SubSystemTwo();
_three = new SubSystemThree();
_four = new SubSystemFour();
}
public override void ProcessA()
{
Console.WriteLine("\nProcessA of Facade uses the following subsystems to accomplish the task:");
_one.MethodOne();
_two.MethodTwo();
_four.MethodFour();
}
public override void ProcessB()
{
Console.WriteLine("\nProcessB of Facade uses the following subsystems to accomplish the task:");
_two.MethodTwo();
_three.MethodThree();
}
}
}
감사합니다. 간단하게하기 위해. 하지만 내 주요 질문은 파사드 클래스 추상 만들기의 사용은 무엇입니까. 어떻게 추상적 인 수업이 도움이됩니까? –
외관 클래스를 추상 클래스로 지정하는 것은 필수 사항이 아닙니다. 그들은 또한 구체적인 수업이 될 수 있습니다. 추상적 인 Facade 클래스는 객체가 다른 객체와 기능에 액세스 할 수 있도록하는 기본 인터페이스를 제공하고 실제 구현이이를 준수하도록 도와줍니다. – Jayendra
안녕하세요, 추상 클래스에 대한 내 손을 시도하고 위의 동일한 프로그램에 대한 코드를 게시 ... 확인하시기 바랍니다 제발 알 수있는 경우 제대로 구현 또는 아닙니다. –