This can be done with simple polymorphism. The solution to this problem is to break those outwards dependencies on the lower level modules. This turns the if/else/switch statements into dependency magnets that reach across large swathes of the system source code, binding the system into a tight monolithic architecture without a flexible component structure. Those higher level modules, therefore, have transitive dependencies upon the lower level modules. Other higher level modules tend to depend on the modules that contains those if/else/switch statements. However, the above diagram shows that it’s worse than that. They thwart our desire to create architectures that are made up of independently deployable components. We don’t like dependencies that run from high level modules to low level modules. This often means that the module containing the if/else/switch will have source code dependencies upon those lower level modules. Such statements tend to have cases that point outwards towards lower level modules. This leads to fragile systems.īut there is a worse problem with if/else/switch statements. The fact that they are replicated in many places is problematic because when such statements are inevitably changed, it is easy to miss some. The proliferation of if/else/switch statements is a common problem in software systems. It’s not inconceivable that you’d find a if/else/switch that used an integer in one case and a string in the next! Some of those if/else/switch statements might switch on the integer, and others might switch on the string. ![]() ![]() My fear is that the if/else/switch chain that the author was asking about is replicated in many more places within the code. However, I have a hard time believing that the business rules of the system are not using that gender code for making policy decisions. …then his refactoring #2 would be my preference.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |