C# 关于好的班级名称的想法
如何命名具有以下公共接口的类:C# 关于好的班级名称的想法,c#,.net,naming-conventions,framework-design,C#,.net,Naming Conventions,Framework Design,如何命名具有以下公共接口的类: /// <summary> /// Enqeues and exectutes actions synchronously on seperated threads using the <see cref="ThreadPool"/>. /// </summary> /// <remarks> /// Syncronism is guaranteed on a per-instance base i
/// <summary>
/// Enqeues and exectutes actions synchronously on seperated threads using the <see cref="ThreadPool"/>.
/// </summary>
/// <remarks>
/// Syncronism is guaranteed on a per-instance base in that each enqued action will be executed
/// after the previous action has completed execution for each instance of <see cref="ThreadPoolExectutor" />
/// </remarks>
internal class ThreadPoolExectutor
{
/// <summary>
/// Initializes a new instance of the <see cref="ThreadPoolExectutor"/> class.
/// </summary>
/// <param name="capacity">The absolute (not the initial) number of elements that the <see cref="ThreadPoolExectutor"/> can contain.</param>
public ThreadPoolExectutor(int capacity)
/// <summary>
/// Occurs when exception occured during execution.
/// </summary>
public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
/// <summary>
/// Enqueues a new action with a single parameter for execution on the thread pool.
/// </summary>
/// <param name="action">
/// The action to enqueue for execution.
/// </param>
/// <param name="param">
/// The parameter for the action.
/// </param>
/// <typeparam name="TArg">
/// The type of the <paramref name="param"/>.
/// </typeparam>
public void Execute<TArg>(Action<TArg> action, TArg param)
/// <summary>
/// Enqueues a new action with no parameters for execution on the thread pool.
/// </summary>
/// <param name="action">
/// The action to enqueue for execution.
/// </param>
public void Execute(Action action)
}
//
///使用在分离的线程上同步执行操作。
///
///
///在每个实例的基础上保证同步,因为每个请求的操作都将被执行
///在上一个操作完成对的每个实例的执行之后
///
内部类ThreadPoolExecutor
{
///
///初始化类的新实例。
///
///可以包含的元素的绝对数(不是初始数)。
公共线程池Executor(int容量)
///
///在执行期间发生异常时发生。
///
发生公共事件事件处理程序异常;
///
///使用单个参数将新操作排队,以便在线程池上执行。
///
///
///要排队执行的操作。
///
///
///操作的参数。
///
///
///类型的。
///
public void Execute(操作,目标参数)
///
///在线程池上执行新操作时,将其排队,但不带参数。
///
///
///要排队执行的操作。
///
公共作废执行(操作)
}
命令和执行行动
我称之为ThreadPoolDispatcher
命令和执行行动
我会将其命名为
ThreadPoolDispatcher
我会将其命名为ThreadPoolManager
我会将其命名为ThreadPoolManager
我个人会尝试将该类重构为两个较小的类,以遵循单一责任主体-因此有一个类来执行操作
ThreadPoolDispatcher[根据我同意的上述建议]
然后是一个ThreadPoolQueuer
,它将负责对线程进行排队
尽管只是个人喜好,但我个人会尝试将类重构为两个较小的类,以遵循单一责任原则-因此有一个类来执行操作 ThreadPoolDispatcher[根据我同意的上述建议] 然后是一个
ThreadPoolQueuer
,它将负责对线程进行排队
虽然只是个人喜好那么
ThreadPoolAgent
呢那么ThreadPoolAgent
呢我想说一些类似的话,但是名字应该表明工作中有一种排队机制,所以你的线程不会立即被调度。这比“导师”好得多,因为我在课堂上没有看到任何教程,而且它似乎对任何人都不是“执行官”,也不是“执行”任何人:)@Justin Niessner我不同意。队列是类的内部构件,不应公开。我认为Dispatcher具有足够的描述性,这意味着它以它认为最好的方式处理线程。我将其重命名为ThreadPoolDispatcher
,并将Execute
方法重新发送到Invoke
。这与System.Windows.Threading.Dispatcher
相匹配。我想说一些类似的话,但名称应该表明工作中存在排队机制,因此线程不会立即被调度。这比“导师”要好得多,因为我在课堂上没有看到任何教程,而且它似乎既不是“执行”也不是“执行”任何人:)@Justin Niessner我不同意。队列是类的内部构件,不应公开。我认为Dispatcher具有足够的描述性,这意味着它以它认为最好的方式处理线程。我将其重命名为ThreadPoolDispatcher
,并将Execute
方法重新发送到Invoke
。这与System.Windows.Threading.Dispatcher
相匹配。manager是个坏名字-它似乎表示一个神级,好的设计原则告诉我们要远离这些类型的类。我希望我的所有类都像神一样,并在啤酒盒中激发敬畏:)manager是个坏名字-它似乎表示神级和好的设计原则告诉我们要远离这些类型的课程我希望我所有的课程都像上帝一样,并在啤酒盒中激发敬畏:)为什么你有两种不同的执行(Action,T)?可以使用lambda表达式关闭任何参数。这个类看起来也很像System.Threading.Tasks.TaskScheduler。“enques and executes”“管理队列并执行”也许:)我想建议SerialTaskDispatcher
作为答案,但是@Strilanc提到了一个具有类似功能的类,这似乎是一个更好的选择。命名是编程中最难的部分:通常没有一个正确的答案。@bitbonk我不是说你应该使用Object,我是说函数根本不应该存在[因为你可以只使用Execute(()=>OnStart](itemToStart)))。此外,TaskScheduler可以同步执行调用。事实上,我编写并使用了一个线程池,一个接一个地运行调用。为什么有两个不同的execute(Action,T)?可以使用lambda表达式关闭任何参数。这个类看起来也很像System.Threading.Tasks.TaskScheduler。“enques and executes”管理队列并执行“maybe:)我本打算建议将SerialTaskDispatcher
作为答案,但@Strilan提到的具有类似功能的类似乎是更好的选择。命名是编程中最难的部分:通常没有唯一正确的答案。@bitbonk我不是说你应该使用Object,我是说函数应该ldn根本不存在[因为你可以只使用Execute(()=>OnStart(itemToStart))]。此外,TaskScheduler可以同步执行调用。事实上,我编写并使用了一个线程池,一个接一个地在线程池上运行调用。使用YAGNI,只要我需要seprate排队策略,我就会按照你的方式重构它。(我不知道这种思维方式是否明智)。与雅格尼一起,我会在需要seprate que时尽快按照你的方式重构它