2013-06-09 2 views
1

아래 스 니펫에는 동일한 프로 시저 이름을 가진 두 개의 클래스가 있습니다. 이 절차의 코드는 실질적으로 다릅니다. 이 수업을보다 쉽게 ​​유지 보수하고 향후 개선 할 수 있도록 통합 할 수 있습니까? 아니면이를 수용할만한 방식으로 진행할 수 있습니까?여러 클래스를 통합하는 모범 사례

type 
    TMFRCore = class 
    private 
     FGridMain: TNextGrid; 
     FGridSummary: TNextGrid; 
    public 
     constructor Create(Grid: TNextGrid; SummaryGrid: TNextGrid); 
     destructor Destroy; override; 
     procedure SetRowColour(Grid: TNextGrid; Row: Integer; Color: TColor; Start: Integer = 0); 
     procedure OnSummaryDblClick(Sender: TObject); 
     function GetSectionId(Section: String): Integer; 

     property GridMain: TNextGrid read FGridMain write FGridMain; 
     property GridSummary: TNextGrid read FGridSummary write FGridSummary; 
    end; 

type 
    TMFRDates = class(TMFRCore) 
    public 
     procedure UpdateSummary; 
     procedure UpdateMain(const sAircraft: string); 
    end; 

type 
    TMFRHours = class(TMFRCore) 
    public 
     procedure UpdateSummary; 
     procedure UpdateMain(const sAircraft: string); 
    end; 

이러한 클래스는 다음과 같이 초기화됩니다.

procedure TfrmMain.FormCreate(Sender: TObject); 
begin 
    MFRHours := TMFRHours.Create(gridHours, gridHoursSummary); 
    MFRDates := TMFRDates.Create(gridDates, gridDatesSummary); 
end; 

답변

3

당신은 당신이 동적 파견 다형성을 활용할 수 있도록 기본 클래스의 가상 (아마도 추상)로 메소드를 선언 할 수 있지만, 그렇지 않으면 통합 할 아무것도 정말 없다. 이러한 클래스에 공통된 것은 모두 이미 하나의 기본 클래스에 있습니다. 이 선언을 추가하면 실제로는 기존 메서드 선언 및 구현을 유지해야하기 때문에 코드가 코드임을 의미합니다.

+0

답장을 보내 주셔서 감사합니다. 나는 내가가는 길을 계속할 것 같아. 마침내 내 경로가 대중에게 받아 들여질 수있는 델파이에서 진전을 이뤄내는 것이 좋습니다. :) – Dan