Solved

What are PARTIAL CLASSES and what are the scenarios I should be using them?

Posted on 2014-01-29
2
220 Views
Last Modified: 2014-01-30
Can anyone please explain me what PARTIAL CLASSSES are?
In what scenarios we can use and when should we use them?
0
Comment
Question by:RajG1978
2 Comments
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 250 total points
Comment Utility
Partial classes span the implemention over multiple files.
It can be used for:
Separate generated  code from your working code. E,g. Winforms, add functionality to web service imported classes.
Separate commonly-edited code from rarely-edited code. E.g. You have some code that does not change at all but you want to provide more functionality with your class.
In other words you can grow a class without using inheritance.
For further info check:
http://www.dotnetperls.com/partial
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
Comment Utility
Partial classes are classes whose code is distributed over more than one file.

Windows Forms used if for instance to separate the code written by the programmer and the code generated by the Forms Designer. When you design a form, the code generated ends up in a Partial Class FormName located in a FormName.designer.vb (or .cs in C#), while the code written by the programmer to react to events and makes the form work is also define in a Partial Class FormName contained in a second FormName.vb file. When you compile, the compiler treats the code in the 2 files / 2 partial classes as a single class.

Although it is not used often for other uses, one could thing for instance of a Photo class that is reused across many applications. Some applications use that class in relation with a database that gives information about the photos. Other applications do not care about the database and deal only with the data that comes straight from photo files on the hard disk.

One could like to split that class into 2 partial classes. The first partial contains the general code to work with photos, while the second one contains only the constructors, methods and properties that deal with the database aspect.

In projects that need to work with the database, you include the 2 files. In projects that do not need the database, you include only the main file. That way, you do not carry in the application the database code that would be useless.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now