I create private method, with different input data, it works differently.
private void SetSelectedRouters(bool isSelected)
{
for (int i = 0; i < m_listPlatforms.Count; i++)
{
m_listPlatforms[i].IsCheked = isSelected;
}
}
And create public method for interaction.
public void SelectedAllRouters()
{
开发者_如何学JAVASetSelectedRouters(true);
}
public void SelectedNoneRouters()
{
SetSelectedRouters(false);
}
I think this is encapsulation, or as something in a different name?
I'd say it's more code reuse, extracting the common functionality within two methods so that those methods become trivial, simply calling a common method.
(I'd encourage you to use foreach
to improve the readability further, by the way.)
This isn't encapsulation. It's an extracted method. All of the code in the method is relevant to one other and its purpose is clearly described in its name. This is also called a helper method.
Wikipedia claims:
In a programming language encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination[1][2] thereof:
1. A language mechanism for restricting access to some of the object's components.
2. A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.
So to me it seems yes (by looking at second point)
精彩评论