0

Apart of the atypical reasons to have classes with hundred members (eg DAO pattern to access hundred objects), what would be the best approach: Have only one class with all members or instead hundred of partial classes each one with one member ?

One partial class for each member looks nice because it facilitates the construction of automated solutions to insert and delete members, just creating or deleting files (classes).

Does C# or something in .Net limit the amount of partial classes ? What about others performances or resources consumption at design time or compilation, supposing that at runtime the two alternatives are the same ?

DETAILING A SAMPLE: Databases with hundred of objects that need to be accessed from a DaoFactory (DAO pattern) would typically has one member to each object in the database. We aren't discussing the business behind that, why this system has and how it works, but we have a situation, and all objects need to be "exposed" by a DaoFactory. Of course, multiple DaoFactories grouping the objects can minimize its size (amount of members), but only if the division consider all possible relations between them, so all possible of database transactions combined among them to group them.

So, supposing that we cannot divide this DaoFactory, we have a class with hundred of members, and partial classes is an alternative like the one I asked, to have a kind of tool that can maintain it just creating or deleting partial class to each member.

Luciano
  • 2,695
  • 6
  • 38
  • 53
  • 8
    *hundred of partial classes each one with one member* you can't be serious, right? –  Aug 16 '13 at 20:00
  • 1
    Honestly, I think it's a perfectly valid code-gen question. If this code were hand-maintained I would have the same objection, @Will, but machine-generated code is a different beast entirely. – cdhowie Aug 16 '13 at 20:02
  • 1
    I can't imagine 100 people all needing to change a class at once – Sayse Aug 16 '13 at 20:03
  • @cdhowie: Why on earth would code generated by a tool need more than one partial? If your code gen is so slow it can't be allowed to regen a single method then you're doing it wrong. And even in that case, you could simply peek into the gen file for what you want to change and just alter that. No need to create piles of useless files. –  Aug 16 '13 at 20:06
  • Please, look the "detailed sample" – Luciano Aug 16 '13 at 20:59
  • @Will, my question isn't about the business behind the system. Anyway, some tools can collaborates with manual editing, and not just gen 'untouchable' code. Consider this special case (big class) where an addition or removal of a member could be done just creating or deleting a partial class, made a tool or by manual edit. – Luciano Aug 16 '13 at 21:03
  • Even if your class had 100 members, why would you need to create partial classes? All 100 members can be inside the same class. Managing one hundred different files for each partial class would cause its own issues. – ataravati Aug 16 '13 at 21:46
  • @ataravati: Thanks by the effort in helping. So, I don't gave a lot of detail about the needs because it ins't why I'm asking. I described a kind of needs just to illustrate a case. But what I'm asking is about the issues that we could have if adopted the use of a partial class for each member (hundred members). Any help or opinion is appreciated but please, focus on my question. – Luciano Aug 17 '13 at 16:47

2 Answers2

5

That's not what partial classes are used for. Partial classes are supposed to be used when you do not want to touch the code in the main class. A very good example is the code generated by EF.

Or, when a couple of developers want to work on the same big class. They each develop part of the class as a partial class.

But, you don't divide a class into partial classes just because the class is big.

ataravati
  • 8,891
  • 9
  • 57
  • 89
  • 4
    Not to mention that a gigantic class is a code smell indicating a probable lack of good object and violation of the principle of Single Responsility. A class has 100 [public?!] members quite probably needs to be refactored into a bunch of smaller, simpler classes. – Nicholas Carey Aug 16 '13 at 20:12
  • @NicholasCarey: Yes. But smell doesn't mean that something is really rotten (look the detailed sample, please) – Luciano Aug 16 '13 at 21:12
0

What would be the point of a class with a hundred, quite likely unrelated members.

If your're going to be generating code, as it appears you might from it facilitates construction of automated solutions... to do data access, create an abstract class or classes, possibly (likely, in fact) generic that implements the common functionality required.

Have your code generator construct suitable concrete instance of the same.

This approach works for manual construction as well.

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135