Click here to Skip to main content
15,914,327 members
Home / Discussions / C#
   

C#

 
QuestionPerformance: Partial Classes vs Inheritence? Pin
matsnas19-Apr-07 22:11
matsnas19-Apr-07 22:11 
AnswerRe: Performance: Partial Classes vs Inheritence? Pin
Colin Angus Mackay19-Apr-07 22:27
Colin Angus Mackay19-Apr-07 22:27 
GeneralRe: Performance: Partial Classes vs Inheritence? Pin
matsnas19-Apr-07 22:58
matsnas19-Apr-07 22:58 
GeneralRe: Performance: Partial Classes vs Inheritence? Pin
Colin Angus Mackay20-Apr-07 0:10
Colin Angus Mackay20-Apr-07 0:10 
GeneralRe: Performance: Partial Classes vs Inheritence? Pin
matsnas20-Apr-07 0:40
matsnas20-Apr-07 0:40 
GeneralRe: Performance: Partial Classes vs Inheritence? Pin
Luc Pattyn20-Apr-07 3:31
sitebuilderLuc Pattyn20-Apr-07 3:31 
GeneralRe: Performance: Partial Classes vs Inheritence? Pin
Colin Angus Mackay20-Apr-07 3:45
Colin Angus Mackay20-Apr-07 3:45 
AnswerRe: Performance: Partial Classes vs Inheritence? Pin
Scott Dorman20-Apr-07 3:25
professionalScott Dorman20-Apr-07 3:25 
Partial classes provide no benefit at runtime, they are a compile-time only feature of the language. At compile time, the compiler takes the collection of partial classes for the type (in your example above, this would be the two partial myClass bodies from myClass.cs and myClass.base.cs) and compiles them to a single runtime type.

As Colin pointed out, partial classes were designed to solve a different set of problems than inheritance and shouldn't be used in place of inheritance.

Partial classes are great when you want to isoloate groups of functionality for the same class (like separating all of the event handler logic) or need to provide the ability for multiple people to work in the same type at the same time without stepping on each other's changes.

The partial class can be in any file, but must be named the same as the other partial classes for that type. This prevents the same partial class from being used by other partial classes. This is what Colin meant by "code bloat". If you have multiple classes that need to share functionality, putting it in a partial class will require multiple partial classes with the same code in each, which will create a lot of problems beyond code bloat (think about fixing the same bug in multiple locations).

Inheritance was designed to provide common characteristics and behavior for multiple derived (inherited) types. The benefit here is that these common traits only need to be written and compiled once.



-----------------------------
In just two days, tomorrow will be yesterday.

QuestionConversion of LastModified method Pin
Amatista19-Apr-07 22:05
Amatista19-Apr-07 22:05 
AnswerRe: Conversion of LastModified method Pin
Jupiter920-Apr-07 7:32
Jupiter920-Apr-07 7:32 
GeneralRe: Conversion of LastModified method Pin
Amatista22-Apr-07 22:41
Amatista22-Apr-07 22:41 
QuestionControl.Visible Property Problem Pin
alashara19-Apr-07 21:43
alashara19-Apr-07 21:43 
AnswerRe: Control.Visible Property Problem Pin
Guffa19-Apr-07 23:05
Guffa19-Apr-07 23:05 
GeneralRe: Control.Visible Property Problem Pin
alashara20-Apr-07 2:44
alashara20-Apr-07 2:44 
QuestionSending more then 28 file names to string array in app creates error Pin
Yoav Ben Zvi19-Apr-07 21:34
Yoav Ben Zvi19-Apr-07 21:34 
AnswerRe: Sending more then 28 file names to string array in app creates error Pin
Yoav Ben Zvi20-Apr-07 0:29
Yoav Ben Zvi20-Apr-07 0:29 
AnswerRe: Sending more then 28 file names to string array in app creates error Pin
Luc Pattyn20-Apr-07 3:34
sitebuilderLuc Pattyn20-Apr-07 3:34 
QuestionCombobox in my DataGridView? Pin
akkram19-Apr-07 21:31
akkram19-Apr-07 21:31 
QuestionTreeView Pin
mihksoft19-Apr-07 21:27
mihksoft19-Apr-07 21:27 
AnswerRe: TreeView Pin
Yoav Ben Zvi19-Apr-07 21:38
Yoav Ben Zvi19-Apr-07 21:38 
QuestionXML Help Pin
umashankergr819-Apr-07 21:25
umashankergr819-Apr-07 21:25 
AnswerRe: XML Help Pin
Stefan Troschuetz19-Apr-07 21:29
Stefan Troschuetz19-Apr-07 21:29 
QuestionImage processing in Visual Studio C# .Net Pin
zeeShan anSari19-Apr-07 21:25
zeeShan anSari19-Apr-07 21:25 
AnswerRe: Image processing in Visual Studio C# .Net Pin
shrinerainxp19-Apr-07 21:52
shrinerainxp19-Apr-07 21:52 
QuestionTo Check a Window Service on C#.Net Pin
biswabhusan19-Apr-07 21:22
biswabhusan19-Apr-07 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.