我有一个有很多方法的课程:
public class MyClass { public bool checkConditions() { return checkCondition1() && checkCondition2() && checkCondition3(); } ...conditions methods public void DoProcess() { FirstPartOfProcess(); SecondPartOfProcess(); ThirdPartOfProcess(); } ...process methods }将这两个类都设置为MyClass的内部类?
我有2个选项:我在MyClass定义它们,将所有内容都放在同一个文件中,这看起来令人困惑和丑陋,或者我可以将MyClass定义为一个partial class , MyClass有一个文件, MyClassConditions有另一个文件, MyClassConditions其他。
将它们定义为内部?
我不太喜欢那些内部修饰符,因为我没有发现这些类为我的程序/程序集的其余部分添加了任何值,并且我想尽可能隐藏它们。 这并不像他们在程序的其他任何部分会有用/可重用。
让他们公开?
我看不出为什么,但我已经让这个选项在这里。
任何其他?
命名它!
谢谢
I had a class that had lots of methods:
public class MyClass { public bool checkConditions() { return checkCondition1() && checkCondition2() && checkCondition3(); } ...conditions methods public void DoProcess() { FirstPartOfProcess(); SecondPartOfProcess(); ThirdPartOfProcess(); } ...process methods }Setting both classes as inner classes of MyClass?
I have 2 options: I either define them inside MyClass, having everything in the same file, which looks confusing and ugly, or I can define MyClass as a partial class, having one file for MyClass, other for MyClassConditions and other for MyClassProcessExecution.
Defining them as internal?
I don't really like that much of the internal modifier, as I don't find these classes add any value at all for the rest of my program/assembly, and I'd like to hide them if possible. It's not like they're gonna be useful/reusable in any other part of the program.
Keep them as public?
I can't see why, but I've let this option here.
Any other?
Name it!
Thanks
最满意答案
你最好的选择可能是使用部分类,并将三个代码块放在单独的文件中,并添加到同一个类中。 然后,您可以将条件代码和流程代码设为私有,以便只有类本身才能访问它们。
Your best bet is probably to use partial classes and put the three clumps of code in separate files adding to the same class. You can then make the conditional and process code private so that only the class itself can access them.
更多推荐
发布评论