?
Solved

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

Posted on 2014-01-29
2
Medium Priority
?
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 1000 total points
ID: 39819666
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 1000 total points
ID: 39819968
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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