Groups > Borland > Delphi Object Oriented design > Re: Class and File




Re: Class and File

Re: Class and File
Sat, 08 Mar 2008 08:05:43 +000
Chau Chee Yang a écrit :

> In Java and C#, one single file keep only one class.  Correct me if I am 
> wrong.

I will correct you, you are wrong :-)

C# allows more than one class in a unit. It even allows nested classes.

> Java and C# are both newer than object pascal.  Is that true that one 
> file one class approach is better although I am get use to the object 
> pascal.

How many classes you put in the same unit depends on the closeness of 
their relationship. One class per file is a good target to aim for, it 
certainly avoids the monster units that I have sometimes come across.

But there are times when two or more classes are very closely related 
and could well share a unit.

> But C# has namespace, object pascal has packages.  Both seems to have 
> same deployment strategy.

C# has namespaces and also assemblies. Assemblies are the .NET 
equivalent of Delphi packages, not namespaces.

Namespaces can be split over more than one assembly.

Don't forget that Delphi for .NET also has namespaces.

Joanna

-- 
Joanna Carter [TeamB]
Post Reply
Re: Class and File
Sat, 8 Mar 2008 08:46:27 -0500
On Sat, 08 Mar 2008 08:05:43 +0000, Joanna Carter [TeamB] wrote:

> C# allows more than one class in a unit. It even allows nested classes.
It even allows multiple namespaces in the same file.

For my 2c, in C# I never put more than one class in a file (except for
nested classes), I find it easier to manage that way.

In Delphi, I generally follow the same rule, although there are times
when the I am forced to (for example I often have a list and its items
together in a file)

-- 
Marc Rohloff [TeamB]
Post Reply
Class and File
Sat, 08 Mar 2008 11:42:32 +080
Hi,

Java, C# and object Pascal supports OO languages.

In Java and C#, one single file keep only one class.  Correct me if I am 
wrong.

But for object pascal, one file (unit) may keep more than one class.

Java and C# are both newer than object pascal.  Is that true that one 
file one class approach is better although I am get use to the object 
pascal.

But C# has namespace, object pascal has packages.  Both seems to have 
same deployment strategy.

-- 
Best regards,
Chau Chee Yang

E Stream Software Sdn Bhd
URL: www.sql.com.my
Post Reply
Re: Class and File
Sat, 08 Mar 2008 19:30:41 +000
Marc Rohloff [TeamB] a écrit :

> It even allows multiple namespaces in the same file.

:-)

> For my 2c, in C# I never put more than one class in a file (except for
> nested classes), I find it easier to manage that way.

As a principle, that is what I usually adhere to. The only other 
"excuses" I use are when I have a base non-generic class or interface

and a derived generic version :

public abstract class Thing
{
   ...
}

public class Thing<T> : Thing where T : Thing<T>
{
   ...
}

...very useful for solving covariance problems, and not worth a separate 
unit :-)

> In Delphi, I generally follow the same rule, although there are times
> when the I am forced to (for example I often have a list and its items
> together in a file)
> 


-- 
Joanna Carter [TeamB]
Post Reply
Re: Class and File
Sun, 09 Mar 2008 20:24:28 +080
Joanna Carter [TeamB] wrote:
> 
> I will correct you, you are wrong :-)
> 
> C# allows more than one class in a unit. It even allows nested classes.

Java also allows more than one classes in one source file.
But only one can be public.


-- 
Denomo: memory and resource leak detection tool, free open source
CodeHook: Win32 code/API hook for Delphi & C++, free open source
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact