[Lazarus] OOP basics - 2

Michael Van Canneyt michael at freepascal.org
Thu Apr 15 10:37:09 CEST 2010



On Thu, 15 Apr 2010, Juha Manninen wrote:

>> I agree with Michael here. "Put everything in one big file" is a pure evil,
>> equivalent to "I do not want to think about proper design, let's just
>> pile all the code in one big heap"
>
> I don't know what is wrong with you guys. SW design can be good even if it has
> interdependent classes. It depends on the original problem scope.
> This is from Michael's other mail:
>
>> If that is really the case they should be in the same unit, and the
>> problem is moot.
>>
>> It's not for nothing that TCollection and TCollectionItem are in the
>> same unit.
>
> Right, so the original comment
> "In more than 20 years of pascal programming, I never encountered this
> problem."
> actually means to copy everything into one file.
> That's what I was saying, too! :-)

Nono, you should not put words in my mouth which I didn't say nor mean.

>
> If I understand right, Michael and Mattias have made big parts of Lazarus core
> which I referred to. They have used types casting to avoid circular
> references. Now they say they never encountered this problem.

Well, I didn't create any of the code you are referring to.
I never use typecasts of the sort described in the mail.

Then: TCollection/TCollectionItem were defined by Borland.

Regarding that particular example:
They are so closely bound together that it makes no sense to put them
in separate units. If someone wanted to put them in separate units,
he would have some serious explaining to do regarding the need for that.

For the rest: I have a code base of  many millons of lines. Nowhere I
have encountered the problems you describe. No circular dependencies,
no need for huge files either. A typical unit contains 4, maybe 5 classes, 
in rare cases 10. And those classes are always closely bound together, 
so it simply makes sense to put them in 1 unit.

As a nice side effect, it makes the uses clauses more simple. If every class
I ever used was in a separate unit, the uses clauses would simply explode;
Delphi (or FPC) has trouble enough finding the files it needs. As it is, a 
typical project takes 15 minutes to compile with delphi on a recent machine. 
I can't imagine what would happen if I put every class in a separate unit...

To summarize: All I wanted to say is that

1. I don't think that each class should be in it's own unit; If it is
    beneficial to do so, I will. If not: I don't.

2. The structure of my classes has never forced me to solve circular references
    by throwing classes together in 1 unit, or by using strange typecasts.

Michael.




More information about the Lazarus mailing list