Is Partial Class feature required

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Would like to know from the crowd that why do we require a Partial Class. By
having such feature aren't we going out of the scope of Entity Concept.

Help me to understand in what context this feature is better and when it is
not.

Thanks for reading
 
Dara P said:
Would like to know from the crowd that why do we require a Partial Class. By
having such feature aren't we going out of the scope of Entity Concept.

Help me to understand in what context this feature is better and when it is
not.

The main area where they're useful is with generated code, where you
want some of the code for a class to be autogenerated (e.g. by a
designer, or ORM system) and some to be hand-coded. Partial classes are
a good way of achieving this.
 
It is really helpful in separating tool-generated code from developer-written
code so that one cannot mess up other's code.
 
Would like to know from the crowd that why do we require a Partial Class. By
having such feature aren't we going out of the scope of Entity Concept.

Help me to understand in what context this feature is better and when it is
not.

Thanks for reading

Hey,

I would like to add to above reasons the team work on partial
classes.

You can distribute class development across class development team and
working parallel, without having to mess things up,
 
And further to Maverick... I find this useful when a class gets large,
perhaps because it needs to implement a series of non-trivial
interface (e.g. for a complex binding collection, IList, IList<T>,
ICollection, ICollection<T>, IEnumerable, IEnumerable<T>, ITypedList,
IBindingList, IBindingListView, ICancelAddNew,
IRaiseItemChangedEvents, etc); *plus* the actual implementation
itself, and perhaps a few static helper methods... so until Jon's
"proxies" suggestion makes it to the compiler, I find it useful to
split related portions of the classs into a few partial classes... but
not one file each - a file just for IRaiseItemChangedEvents would be
counter-productive...

Marc
 
I agree with you on one point that, by using the Partial class feature we are
deviating from the concept of Closed Entity. With this feature, you are never
aware that the class diagram what initially planned is going to be the same
as the versions of the application is growing.

On the contrary, it is a facilitation to the developers to make the progress
quick with multi developer working on a single Entity.

Again, it is upto you, whether to use it not to use it. Microsoft provides
you the facility, so you are the architect of your application, take the
feature or leave.

HTH
 
I agree with you on one point that, by using the Partial class feature we are
deviating from the concept of Closed Entity. With this feature, you are never
aware that the class diagram what initially planned is going to be the same
as the versions of the application is growing.

I don't think it breaks the closed entity concept. All the partial
keyword does is tell the compiler that the class' code is split into
two or more files. It doesn't change anything about the class itself.
 
I don't think it breaks the closed entity concept. All the partial
keyword does is tell the compiler that the class' code is split into
two or more files. It doesn't change anything about the class itself.

I agree with Andy. There's no weakening of encapsulation here: private
fields are still private, protected methods are still protected. The
difference is that the implementation is split among multiple files.

I agree that the latter could be confusing: you could read one file
and think that it contains the entire implementation when in fact it
doesn't. Incapsulation, however, is still intact.
 
Would like to know from the crowd that why do we require a Partial Class. By
having such feature aren't we going out of the scope of Entity Concept.

Help me to understand in what context this feature is better and when it is
not.

Thanks for reading

One particular area where I find myself taking advantage of partial
classes is strongly typed datasets. I often want to extend the
dataset without subclassing. Since the designer creates the dataset
in the separate partial class file I can add my own methods without
mucking up the designer code.
 
With this feature, you are never
aware that the class diagram what initially planned is going to be the same
as the versions of the application is growing.

Don't forget that all members still show in the selectors (along with
handy indication of which are in the current file), and all members
appear in intelli-sense, visual tools, reflection, etc.

I personally don't see how it is any different to using a single file,
since in an editor I can only see one page of code at a time anyway,
so I rely on other tools such as member diagrams [matron!].

Marc
 
Of course, C++ has always had the concept of "partial implementation." The
whole declaration had to be in one file, but there could be any number of
files to implement the methods.

///ark
 
Am Thu, 10 May 2007 07:42:43 +0100 schrieb Jon Skeet [C# MVP]:
The main area where they're useful is with generated code, where you
want some of the code for a class to be autogenerated (e.g. by a
designer, or ORM system) and some to be hand-coded. Partial classes are
a good way of achieving this.

Don't limit it to that. Partial classes are a means to separate larger
classes into logical units. Such units *can* be autogenerated code vs. code
maintained manually.

E.G., I use it to separate unintersting parts (for example,
drag&drop-implementations) from the intersting parts of a class.

Paule
 
Paul Werkowitz said:
Don't limit it to that. Partial classes are a means to separate larger
classes into logical units. Such units *can* be autogenerated code vs. code
maintained manually.

I wasn't limiting it at all - just saying that its *primary* use is for
generated code. Given the web services, forms, datasets etc which are
generated as partial classes in Visual Studio, I strongly suspect that
the number of partial classes involving autogenerated code vastly
outnumbers the number of partial classes which are entirely manually
generated.

That in no way says that the feature can't be useful for manual code.
 

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

Back
Top