- Published: Thursday, 24 March 2016 09:11
- Written by Vladyslav Taranov
Commenting to Are #regions an antipattern or code smell? I disagree with that one should extract methods instead of creating regions in existing method.
In OOP you should not have unnecessary private methods, as it is more a part of functional programming.
It is better to make a class if you aren't going to reuse extracted methods. There is no sense to have one more private method if it is called from only one place and you have to navigate there to understand what it does so I prefer scopes and regions instead of private methods when it is not too nested.
But there is a sense to have a class even if it's used only in one place because you can refactor it to use interface and substitute implementation.
- Class - use when extracted things are not too tied to a source class, otherwise:
- Regions - use when code is not too nested and no duplicated logic, otherwise:
- Private methods - only for reusing things strongly tied to a source class (DRY!).