Refactoring to pattern