partial classes


P

Peter

Hi

what is the general consensus about partial classes. I have only ever
used them where they are automatically generated for me, for example
with a web application and code-behind classes.

Now I've just been handed a solution which uses many partial classes -
and the first thing that strikes me is "where's the rest of the class
then?". I haven't looked at the code in-depth, so maybe there's a good
reason behind their use here (something with LINQ I think, but I'm not
up to speed with LINQ either).


/Peter
 
Ad

Advertisements

J

Joe Mayo

Hi Peter,

I only use partial classes that are supported by a tool, like Visual Studio.
Other than that, I never use them in normal development - i.e. I'd never
create a partial class myself. This is just my personal preference and
opinion, but my concerns about introducing partial types that aren't tool
generated are (1) it's easy for the partial class to take on too many
responsibilities, (2) multiple developers adding code that causes a
hard-to-find bug, and (3) difficulty in maintenance because related code is
in different files.

Joe
http://www.csharp-station.com
 
P

Peter Morris

Although I do myself sometimes find myself with a valid very large class, it
is also an indication that your class is taking on too much responsibility.

Just thought I'd mention it :)
 
A

Arne Vajhøj

Peter said:
what is the general consensus about partial classes. I have only ever
used them where they are automatically generated for me, for example
with a web application and code-behind classes.

Now I've just been handed a solution which uses many partial classes -
and the first thing that strikes me is "where's the rest of the class
then?".

I would consider multiple files manually maintained to be
a problem.

The feature was added for code generation and should only
be used for that.

Arne
 
P

Peter

Peter said:
what is the general consensus about partial classes

Thanks for the replies. I think for my own work I'll leave partial
classes up to automatic tools - and won't be creating any manually.
I've never had to create really huge classes myself, so never run into
the possibility of deciding to split it up into partial classes.

I'll need to dig deeper into the current project I have to find out why
there are partial classes (none are very big); maybe they were
generated automatically - but there is no nice display of them in in
Visual Studio, like with code-behind files, .ascx files and "designer"
files.

Actually, is it possible to get Visual Studio to find and group all
related partial files for a partial class?

Thanks,
Peter
 
Ad

Advertisements

J

Jeff Johnson

Actually, is it possible to get Visual Studio to find and group all
related partial files for a partial class?

Group, no. Find, yes. Well, basically: you could just search for the whole
word "partial."
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top