Design smells warn of problems in relationships among classes Many catalogs of

Design smells warn of problems in relationships among

This preview shows page 416 - 418 out of 517 pages.

Design smells warn of problems in relationships among classes Many catalogs of code smells and refactorings; we use Fowler’s as definitive Many catalogs of design smells and design patterns; we use Ruby-specific versions of the Gang of Four (GoF) design patterns as definitive ABC, Cyclomatic Complexity metrics complement code smells with quantitative warnings LCOM (Lack of Cohesion of Methods) metric complements design smells with quantitative warnings Refactoring by extracting methods and moving code within a class Refactoring by extracting classes and moving code between classes SOFA guidelines for good methods ( S hort, do O ne thing, F ew arguments, single A bstraction level) SOLID guidelines for good class architecture ( S ingle responsibility, O pen/Closed, L iskov substitution, dependency I njection, D emeter) Some code smells don’t apply in Ruby Some design smells don’t apply in Ruby or SaaS Figure 11.2: The parallels between the warning symptoms and remedies introduced for individual classes and methods in Chapter 9 and those introduced for inter-class relationships in this chapter. For reasons explained in the text, whereas most books use the I in SOLID for Interface Segregation (a smell that doesn’t arise in Ruby) and D for injecting Dependencies, we instead use I for I njecting dependencies and D for the D emeter principle, which arises frequently in Ruby. As with method-level refactoring, application of design patterns is best learned by doing, and the number of design patterns exceeds what we can cover in one chapter of one book. Indeed, there are entire books just on design patterns, including the seminal Design Patterns: Elements of Reusable Object-Oriented Software ( Gamma et al. 1994 ), whose authors became known as the “Gang of Four” or GoF, and their catalog known as the “ GoF design patterns .” The 23 GoF design patterns are divided into Creational, Structural, and Behavioral design patterns, as Figure 11.3 shows. As with Fowler’s original book on refactoring, the GoF design patterns book gave rise to other books with examples tailored to specific languages including Ruby ( Olsen 2007 ). Since the GoF design patterns evolved in the context of statically typed languages, some of them address problems that don’t arise in
Image of page 416
Ruby. For example, patterns that eliminate type signature changes that would trigger recompilation are rarely used in Ruby, which isn’t compiled and doesn’t use types to enforce contracts. The GoF authors cite two overarching principles of good object-oriented design that inform most of the patterns: Prefer Composition and Delegation over Inheritance. Program to an Interface, not an Implementation. We will learn what these catch-phrases mean as we explore some specific design patterns. Creational patterns Abstract Factory , Factory Method : Provide an interface for creating families of related or dependent objects without specifying their concrete classes Singleton: Ensure a class has only one instance, and provide a global point of access to it.
Image of page 417
Image of page 418

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