unit class_model;

interface

uses class_source, Contnrs;

{$REGION 'КЛАСС "МОДЕЛЬ"'}
type
  TRDModel = class (TObject)
    private
      name: string;
      description: string;
      index: integer;

    public
      sources: TRDSource;

      function Get_model_name: string;
      function Get_model_description:string;
      function Get_model_index:integer;

      constructor Create ( in_model_name, in_model_desc:string; in_index:integer); virtual;
      destructor Destroy; override;
end;
{$ENDREGION}


{$REGION 'КЛАСС "Cущность'}
type
  TRD_Something = class (TObject)
    private
      f_name: string;           //Имя
      f_description: string;    //описание

    public

      function Get_name: string;
      function Get_description: string;
      function Get_index: integer;

      constructor Create ( in_name, in_desc: string; in_index: integer);
      destructor Destroy; override;
  end;
{$ENDREGION 'КЛАСС "Cущность'}

{$REGION 'КЛАСС "Массив Сущностей"'}
type
  TRD_List = class (TObjectList)
    private

    public
      function Find_by_name( in_object_name: string ): TRD_Something;
end;
{$ENDREGION}

implementation
{$REGION 'КЛАСС "МОДЕЛЬ" РЕАЛИЗАЦИЯ'}
constructor TRDModel.Create ( in_model_name, in_model_desc: string; in_index: integer );
begin
Assert( ( in_model_name <> '' ),
        'Входное поле ИМЯ МОДЕЛИ класса RDMODEL пустое!'+'{BC114396-B595-4724-A9F7-CD8141188280}');
  inherited Create;
  self.name := in_model_name;
  self.description := in_model_desc;
  self.index := in_index;

  self.sources := TRDSource.Create;
end;

destructor TRDModel.Destroy;
begin
  self.name := '';
  self.description := '';
  self.index := -1;
  self.sources.Free;
  inherited Destroy;
end;

function TRDModel.Get_model_index: integer;
begin
Assert( ( self.index > -1 ),
        'Поле ИНДЕКС класса МОДЕЛЬ вышло за пределы диапазона!'+'{EB959A51-A49D-4BFC-890D-E8B3B5771FF1}');
  result := self.index;
end;

function TRDModel.Get_model_name: string;
begin
  Assert( ( self.name <> '' ),
          'Поле ИМЯ МОДЕЛИ класса RDMODEL пустое!'+'{079AF181-468B-4D3D-B461-2DB577A365AD}');
    result := self.name;
end;

function TRDModel.Get_model_description: string;
begin
    result := self.description;
end;
{$ENDREGION}

{$REGION 'КЛАСС "Массив Сущностей" РЕАЛИЗАЦИЯ'}
function TRD_List.Find_by_name( in_object_name: string): TRD_Something;
var i: integer;
begin
result := nil;
if ( in_object_name <> '' ) then
  begin
    for i := 0 to self.Count - 1 do
    begin
      if ( ( self[ i ] as TRD_Something ).Get_name = in_object_name ) then
      begin
        result := self[ i ] as TRD_Something;
      end;
    end;
  end;
end;



{$ENDREGION}


{ TRD_Something }

constructor TRD_Something.Create(in_name, in_desc: string; in_index: integer);
begin
  inherited;
Assert( ( in_name <> '' ),
        'Входное поле ИМЯ СУЩНОСТИ класса RDSomething пустое!'+'{01A9B53C-F9C2-4501-9C17-23C7B7A1C51D}');

  self.f_name := in_name;
  self.f_description := f_description;
end;

destructor TRD_Something.Destroy;
begin
  self.f_name := '';
  self.f_description := '';
  inherited;
end;

function TRD_Something.Get_description: string;
begin
   result := self.f_description;
end;

function TRD_Something.Get_name: string;
begin
 Assert( ( self.f_name <> ''),
          'Поле ИМЯ СУЩНОСТИ класса RDSomething пустое!'+'{74FAF375-02FB-4916-972B-607F52A944C0}');
   result := self.f_name;
end;

end.
