473,486 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is Partial Class feature required

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
--
Never say, Give up
May 10 '07 #1
12 1656
Dara P <Da***@discussions.microsoft.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 10 '07 #2
It is really helpful in separating tool-generated code from developer-written
code so that one cannot mess up other's code.

"Dara P" wrote:
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
--
Never say, Give up
May 10 '07 #3
On May 10, 9:29 am, Dara P <D...@discussions.microsoft.comwrote:
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
--
Never say, Give up
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,
May 10 '07 #4
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
May 10 '07 #5
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
--
Every thing is perfect, as long as you share!!!

Don''t forget to rate the post
"Dara P" wrote:
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
--
Never say, Give up
May 10 '07 #6
On May 10, 11:59 am, Chakravarthy <dskch...@india.comwrote:
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.

May 10 '07 #7
On May 10, 9:34 am, Andy <a...@med-associates.comwrote:
On May 10, 11:59 am, Chakravarthy <dskch...@india.comwrote:
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 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.

May 10 '07 #8
On May 10, 1:29 am, Dara P <D...@discussions.microsoft.comwrote:
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
--
Never say, Give up
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.

May 10 '07 #9
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

May 10 '07 #10
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
May 10 '07 #11
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
May 12 '07 #12
Paul Werkowitz <ne********@primaprogramm.dewrote:
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.
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 12 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
2564
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
16
423
by: Madhuri Mittal | last post by:
Hi, I know that we can define a class over multiple source files using the keyword 'Partial' in C# within a project. Can we define the class over multiple projects using the 'Patial' keyword- I...
16
2625
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
9
5766
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender,...
10
1947
by: Phil Townsend | last post by:
Hello, I have come to like just about everything in VS2005 except for the "partial class" feature. Sometimes when I add a control to a web form, it is not referenced in the partial class ....
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.