Solved

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

Posted on 2014-01-29
2
226 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 250 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 250 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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