Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Important discussion follows:

C# and other language have made partial classes more popular. But isn't this really a tool that have reinvented the subject-orientated programming wheel? What do you guys think? Should subject-orientated programming be taught more and get more focus to help programmers utilize partial classes better? Resources: http://ptsoft.net/tdd/papers/MDSoC_Thesis_MsC_Final.pdf

Low important optional side track for discussion follows:

I my self use a form of subject-oriented when making a space imperium hobby project in unity3d. In unity3d gameobjects (3d models) that exist in the 3d engine can have "scripts" (read classes or any code file) attached to them with some special global functions that can run on each frame. This is a perfect ground to use subject orientated programming. Take for example a fleet gameObject, since i can attach one value class (weight, name, attack, defence), one gameRule class that handles all business logic and if i need a new subject, for example "Raid" i only add a raid class to the gameObject and all these are separated.

These all implements a a general interface for their subject so they can be checked for and accessed by " IRaid = gameObject.GetComponent[of IRaid] if IRaid is not null: code "

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

For example if I model a protocol as a class (or xml, etc) i use a class or maybe a few classes. But, if I ever need to add extra-features on top of those classes, I just keep my code separated by the main class, in another file, (className.Partial.cs) using partial classes. This way it seems to be a cleaner implementation and i know exactly where to go to add/chage stuff.

share|improve this answer
    
Yes this is a great pattern. And this is subject-oriented programming which has been researched seance 1993. So right now in the industry we have a lot of programmers using a feature which their exist research support for, but few people have heard of it and thus can't benefit from research lessons. Which is a problem i think, what do you guys think? –  Sirex Dec 15 '11 at 13:48
add comment

At least in C# the purpose of partial classes is largely to keep the auto-generated code separate from the code typed by programmers, I've never seen a need to have a class separated into two+ files, it seems like if there was a good reason to do that, they probably should just be separate classes.

share|improve this answer
    
The argument is that if they are separated classes (in the seance of different names and one composition the other) you do not gain object design transparancy and can't add new subjects to a class. Damn, is not finshed yet, pressed enter to make a new line, it posted –  Sirex Dec 15 '11 at 13:34
    
Partial classes are also used to allow two developers to work on the same class without the need to merge the class files in the source control since two files are being used. –  Mike L. Dec 15 '11 at 13:38
    
The benefit of subject-oriented programming is that you do not need to interfere with the existing design or existing functions to make the new feature. You essentially just bolt on a feature on the class. And using partial class for this ensures that the new feature is readily available without worrying if it composite in some variable of the class, making new feature transparent. –  Sirex Dec 15 '11 at 13:46
add comment

"Partial classes" is a way to split up the implementation of a class to different files - which is just a physical separation. Fullstop. Nothing more. It does not imply any logical separation per se.

For what purposes one uses this feature is a different thing. Typically this can be used to separate autogenerated code from hand written code. And also you can use it for dividing your class code into logical groups. Or you use it to group methods with names beginning from A-E in one file, F-M in a second and so on (just kidding).

share|improve this answer
    
Yes i recognize that. Put the use of partial class is often to separate logic in to different features. Thus unknowingly utilizing SOP. –  Sirex Dec 15 '11 at 14:01
    
The last suggestion was actually quite doc-y ;) –  mlvljr Aug 8 '13 at 10:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.