based dispatcher Use Strategy or Template Method possibly combined with

Based dispatcher use strategy or template method

This preview shows page 419 - 421 out of 517 pages.

based dispatcher Use Strategy or Template Method, possibly combined with Abstract Factory pattern; use Decorator to avoid explosion of subclasses L iskov Substitution Substituting a subclass for a class should preserve correct program behavior Refused bequest: subclass destructively overrides an inherited method Replace inheritance with delegation I njection of Dependencies Collaborating classes whose implementation may vary at runtime should depend on an intermediate “injected” dependency Unit tests that require ad hoc stubbing to create seams; constructors that hardwire a call to another class’s constructor, rather than allowing runtime determination of which other class to use Inject a dependency on a shared interface to isolate the classes; use Adapter, Façade, or Proxy patterns as needed to make the interface uniform across variants D emeter Principle Speak only to your friends; treat your friends’ friends as strangers Inappropriate intimacy, feature envy, mock trainwrecks (Section 8.10 ) Delegate behaviors and call the delegate methods instead Figure 11.4: The SOLID design guidelines and some smells that may suggest your code violates one or more of them. We diverge a little bit from standard usage of SOLID: we use I for I njecting dependencies and D for the D emeter principle, whereas most books use I for Interface Segregation (which doesn’t apply in Ruby) and D for injecting D ependencies. As with refactoring and legacy code, seeking out design smells and addressing them by refactoring with judicious use of design patterns is a skill learned by doing. Therefore, rather than presenting “laundry lists” of design smells, refactorings, and design patterns, we focus our discussion around the SOLID principles and give a few representative examples of the overall process of identifying design smells and assessing the alternatives for addressing them. As you tackle your own applications, perusing the more detailed resources listed in Section 11.11 is essential.
Image of page 419
Summary of patterns, antipatterns and SOLID: Good code should accommodate evolutionary change gracefully. Design patterns are proven solutions to common problems that thwart this goal. They work by providing a clean way to separate the things that may change or evolve from those that stay the same and a clean way to accommodate those changes. Just as with individual methods, refactoring is the process of improving the structure of a class architecture to make the code more maintainable and evolvable by moving code across classes as well as refactoring within the class. In some cases, these refactorings lead us to one of the 23 “Gang of Four” (GoF) design patterns. Just as with individual methods, design smells and metrics can serve as early warnings of an antipattern —a piece of code that would be better structured if it followed a design pattern. ELABORATION: Other types of patterns As we’ve emphasized since the beginning of this book, judicious use of patterns pervades good software engineering. To
Image of page 420
Image of page 421

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors