你们正在使用<代码>GetMusic(......)方法获取数据。 如果是的话,它会作出太多的努力,在没有实际需要的情况下利用另一个实体。
事实上,在只有一个投入参数的情况下,你可以使用一种习俗。 但是,如果该类别是唯一使用的地方,那么,如果按类别名称所示,<代码>SongSignature就必须在这一类别中具体使用,这是使用 参数袋”的一种不良做法,因为它使易懂。
此外,如果有人说: SongSignature
必须是一个结构,在这一结构中,有一些数据要作内部改动,该名点人将永远不会发生真正的变化,因为每次打上,将使用copy。
即便是一类,你也必须将这一类的出入口改为<>条码<>公开<>/代码>,而且一般来说,这并不是把论点推向一种功能并从某种功能中取得结果的最佳方法,因为你已经从这一方法中获得了分流。
Let s assume the following situation:
If in a team one programmer replaces the parameters with a class SongRequest
, second programmer did not find that it is used as a parameter to a functions (because it lucks info in a name of a class), and changed it to a structure on next iteration, third programmer used this method in such a way, that it have to be a class (for example have used class references inside SongRequest
)... As a result no one did really knowns why something is not working because each of them have dome right thing... There is no excuse to use a class for a local usage instead of implicit declaration of parameters.
Generally you have a good chances to get such a situation in a future, because:
- you are not the one who changes your code (i.e.
GetMusic
)
- someone can review the code and find the class SongReqest useful (so situation goes even worse - from a local usage to a global usage of a class)
- adding the
SongReuest
class can add an additional dependencies for you method (is someone changes this class, most likely you founction will not compile)
- using
SongRequest
as a property bag
locks it usage only as as a class, as mentioned before.
- using this class, you method would probably never share it parameters with other function calls (for what reason?)
- finally, using
SongRequest
class only for passing parameters for a specific function, gives additional memory overhead footprint, because if this method is called often, at one hand, it will create a lot of unnecessary objects in memory have to be garbage collected, in the other hand, if such a method is used rarely, it will be simply not practical to create a class to pass several variables to a single call
只有一个真正的理由使用类别,而不是两个令人信服的论点:你像这种呼吁一样,希望使“比以前更加美好”的所有法典更加 mo,尽管这并不非常实际和有用。
我永远不会建议你制定这样的法典,直到你想做得更好。
Generally, I suppose that using a custom class for passing an arguments for a function is a bad practice.