Replace Parameter with a New Method (Specialize Method)
Chapter "Replace Parameter with Method" describes when and how to remove passing an argument if method can retrieve argument's value. But I came across to a slightly different case - when some method is frequently called with an argument that it can retrieve:
Let class CConfig be defined as:
Let's assume that the following snippet occurs very often throughout the code:
LoadOption() is obviously able to retrieve m_nOptionSelected so why having two calls instead of the one - of the new method - LoadSelectedOption():
Now you can make a single method call, without a need to provide parameters:
No comments:
Post a Comment