Jump to content

Berocoder

Members
  • Content Count

    60
  • Joined

  • Last visited

Posts posted by Berocoder


  1. The code I posted here is heavily simplified. I agree that cyclic dependencies is not good. 

    But basically one class is one table in database for most cases. There is also some transient classes that reside only in memory.

    So this is about relations between classes.

    Many times I want to navigate both from class A to B and from B to A.

    For example class TPerson have a relation to TAddress.
    So to find the address:

     

      vAddress := aPerson.Address,AsString:;

     

    But to find the person who live at an address make also sense

     

      vName := aAddress.Person.AsString;

     

    So one way to break dependency is to use interface. But there are many questions left to work with as the whole framework now assume direct access.

    So I want to work with IAddress and IPerson instead of TAddress and TPerson.

    But at some point I must deal with the concrete class anyway.

     

    About abstract classes, that is a good point. But what happens with the inheritance chain.

     

    TObject
    TBoldMemoryManagedObject   // inherited in framework

    TBoldFlaggedObject                   // inherited in framework

    TBoldSubscribableObject           // inherited in framework
    TBoldElement                              // inherited in framework
    TBoldDomainElement                 // inherited in framework
    TBoldMember                             // inherited in framework
    TBoldObject                                // inherited in framework
    TBusinessClassesRoot                // Dummy
    TAmObject                                 // basic info   
    TAmStateObject                         // have states  

    TPerson                                      // concrete class 

    This is the inheritance tree for TPerson. Is it even possible to use a TAbstractPerson somewhere ?


  2. 18 hours ago, Ondrej Kelle said:

    That's correct.

     

    2 hours ago, David Schwartz said:

    If you have circular references, then you need to re-think your design.

    See https://stackoverflow.com/questions/53980032/how-to-avoid-using-inc-files-for-code-with-delphi for more details. 

     

    But I now believe that interfaces is the correct solutions instead of direct references between the classes.


  3. I found http://docwiki.embarcadero.com/RADStudio/XE2/en/Classes_and_Objects#Forward_Declarations_and_Mutually_Dependent_Classes

     

    I try to create 2 classes. Each of those have a reference to the other.


     

    unit TestA;
    
    interface
    
    uses
      TestB;
    
    type
    //  TTestB = class;
    
      TTestA = class
      public
        M_TestB: TTestB;
      end;
    
    implementation
    
    end.
    
    unit TestB;
    
    interface
    
    uses
      TestA;
    
    type
      TTestB = class
        M_TestA: TTestA;
      end;
      
    implementation
    
    end.

    Got

    [DCC Error] TestA.pas(6): F2047 Circular unit reference to 'TestA'

     

    What is wrong here ?

     

    If I remove TestB from uses and add

     

    TTestB = class;

     

    I got this instead

     

    [DCC Error] TestA.pas(9): E2086 Type 'TTestB' is not yet completely defined

     

     

     

×