Chapter 9. Protection
A refactoring that improves the protection of existing code must do so in a way that doesn’t alter the behavior of the existing code. All three refactorings in this section do just that. Your motivation for applying them may be to improve protection or it may be a standard refactoring motivation, such as to reduce duplication or to simplify or clarify code.
Replace Type Code with Class (286) helps protect a field from assignments to incorrect or unsafe values. This is particularly important when a field controls what behavior gets executed at runtime because an incorrect assignment could put an object into an invalid state. Replace Type Code with Class (286) uses a class rather than an enum to constrain what values may ...
Get Refactoring to Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.