잊지 않겠습니다.

최소 지식 원칙

Book 2009. 1. 7. 11:56

최소 지식 원칙에서의 가이드라인

1. 객체 자체만의 호출

2. 메소드에서 매개 변수로 전달된 객체

3. 그 메소드에서 생성하거나 인스턴스를 만든 객체

4. 그 객체에 속하는 구성 요소

  

public static double GetTemplrature()

{

  // NOTE : 틀린 경우

  Thermoeter thermometer = station.GetThermometer();

  return thermometer.GetTemperature();

}


public static double GetTemperature()

{

  //NOTE : 맞는 경우 

  return station.GetTemperature();

 } 

Posted by Y2K
,

구상되는 기본틀은 모두 Template를 이용하고, Template에서 이용되는 method들을 따로 객체화 시킨다.

  

namespace TemplatePattern

{

  public abstract class SYNCmailBasePannel

  {

    public abstract void LoadPannel();

    public abstract void MoveNextPannel();

    public abstract void MovePreviousPannel();


    public void ArrangeSubControls()

    {

      //NOTE : arrange sub controls

    }


    public void PaintPanel()

    {

      //NOTE : paint panel

    }

  }


  #region Using Strategy Pattern

  public interface ILoginService

  {

    bool Login(string logonName, string password);

  }


  public interface IChangeDisplayName

  {

    bool ChangeDisplayName(string displayName);

  }

   

  public class SYNCmailLoginService : ILoginService

  {


    #region ILoginService Members


    public bool Login(string logonName, string password)

    {

      throw new NotImplementedException();

    }


    #endregion

  }


  public class SYNCmailChangeDisplayNamer : IChangeDisplayName

  {

    #region IChangeDisplayName Members


    public bool ChangeDisplayName(string displayName)

    {

      throw new NotImplementedException();

    }


    #endregion

  }


  #endregion


  public class SYNCmailDisplayPannel : SYNCmailBasePannel

  {

    public IChangeDisplayName iChangeDisplayName;


    public override void LoadPannel()

    {

      throw new NotImplementedException();

    }


    public override void MoveNextPannel()

    {

      iChangeDisplayName.ChangeDisplayName("newDisplayName");

    }


    public override void MovePreviousPannel()

    {

      throw new NotImplementedException();

    }

  }


  public class SYNCmailLoginPannel : SYNCmailBasePannel

  {

    public ILoginService iLoginService;


    public override void LoadPannel()

    {

      //TODO : GET Login information

    }


    public override void MoveNextPannel()

    {

      //TODO :

      // 1. Connection SYNCmail API

      // 2. Check Login Informations

      if ( iLoginService.Login("logonName", "password") )

      {

        //NOTE : Move Next Pannel

      }

    }


    public override void MovePreviousPannel()

    {

      //TODO :

      // Move previous Pannel

    }

  }

}

Posted by Y2K
,

Collection 구현 방법을 노출하지 않으면서 Collection 안에 들어있는 모든 항목에 접근할 수 있게 해주는 방법의 제공

  

항목들에 대한 반복 작업을 일괄적으로 할 수 있도록 해준다.

  

.NET Framework :

System.Collections.IEnumerable  : GetEnumerator()를 통해서 IEnumerator를 얻어낸다.

System.Collections.IEnumerator : 객체에 대한 접근 항목을 보여주는 interface. Current, MoveNext, Reset을 통해서 모든 객체에 대한 일괄적인 접근제어를 한다. 

  

  public class DinnerMenus2 : IEnumerable

  {

    #region IEnumerable Members


    public IEnumerator GetEnumerator()

    {

      throw new NotImplementedException();

    }


    #endregion

  }



  public class DinnerMenus : IEnumerator

  {

    private int position;


    public DinnerMenus()

    {

      position = 0;

    }


    #region IEnumerator Members


    public object Current

    {

      get { throw new NotImplementedException(); }

    }


    public bool MoveNext()

    {

      throw new NotImplementedException();

    }


    public void Reset()

    {

      throw new NotImplementedException();

    }


    #endregion

  }

Posted by Y2K
,