Unit Two

Overview

El alumno entenderá el modelo más utilizado para el desarrollo de aplicaciones Web reconociendo patrones básicos de diseño/implementación y utilizando herramientas de colaboración y mejora de la productividad para producir mejores resultados en menor tiempo.

Contenido Temático

  1. Introducción a los patrones de diseño
  2. Patrón Model View Controller (MVC)
  3. Herramientas de integración: ant y maven
  4. Controlador de versiones de código fuente: git
  5. Estrategia de implementación del modelo basado en casos de pruebas (TDD)
  6. Herramienta de automatización de pruebas: JUnit

Object Oriented Design (OOD)

Software design principles represent a set of guidelines that helps us to avoid having a bad design. According to author Robert C. Martin are 3 important characteristics of a bad design that should be avoided:
  • Rigidity - It is hard to change because every change affects too many other parts of the system.
  • Fragility - When you make a change, unexpected parts of the system break.
  • Immobility - It is hard to reuse in another application because it cannot be disentangled from the current application.
A design principle is a basic tool or technique that can be applied to designing or writing code to make that code more
  • maintainable
  • flexible
  • extensible

OO Principles

  • S ingle Responsability Principle
  • O pen-Closed Principle
  • L iskov's Substitution Principle
  • I nterface Segregation Principle
  • D on't repeat yourself

Single Reponsability Principle

Every object in your system should have single responsability and all the object's services should be focused on carrying out that single responsability. You've implemented the SRP correctly when each of your objects has only one reason to change.

Open-Closed Principle

Classes should be open for extension, and closed for modification. This OCP is all about allowing change, but doing it without requiring you to modify exisiting code. You close clases by not allowying anyone to touch your working code. You open classes by allowing them to be subclassed, extended and reused (your classes are open for extension).

Liskov's Substitution Principle

Subtypes must be substituable for their base types. The LSP is all about well designed inheritance. When you inherit from a base class, you must be able to subtitute your subclass for that base class without things going terribly wrong. Otherwise, you've used inheritance incorrectly!

Interface Segregation Principle

Clients should not be forced to implement interfaces they do not use.

ISP is about business logic to clients communication.

ISP teaches us to respect our clients more than we thought necessary. Respecting their needs will make our code better and our lives as programmers easier.

Instead of one big interface many small interfaces are preferred based on groups of methods, each one serving one submodule. It helps us have a flexible design.

Don't repeat yourself

Avoid duplicate code by abstracting out things that are common and placing those things in a single location.

DRY is about having each piece of information and behavior in your system in a single sensible place.

Design Patterns

At this point we already know:
  • OO Basics
    • Abstraction
    • Encapsulation
    • Polymorphism
    • Inheritance
  • OO Principles
    • S ingle Responsability Principle
    • O pen-Closed Principle
    • L iskov's Substitution Principle
    • I nterface Segregation Principle
    • D on't repeat yourself

Now lets add the a third element to our Design Toolbox: Design patterns.

Design patterns are proven solutions to particular types of problems, help us structure our own applications in ways that are easier to understand, more maintanable, and more flexible.

Catalog of design patterns

Design patterns vary in their granularity and level of abstraction. We can clasify patterns using two different criteria:

  1. Purpose: What the pattern does. DPs are clasified in: creational, structural and behavioral.
  2. Scope: Whether the pattern applies to classes or objects. Class patterns deal with relationships between classes and their subclasses. Object patterns deal with object relationships, which can be changed at run-time and more dynamic.

Design pattern space

Read more ...

Reference

Remember

  • Knowing the Object Oriented basics does not make you a good designer
  • Good OO designs are reusable, extensible and maintanable
  • Patterns show you how to build systems with good OO desing qualities
  • Patterns are proven object-oriented experience
  • Patterns don't give you code, they give you general solutions to design problems. You apply them to your specific application
  • Patterns aren't invented they are discovered
  • Most patterns allow some part of a system to vary independently of all other parts
  • We often try to take what varies in a system and encapsulate it
  • Patterns provide shared language that can maximize the value of your communication with other developers

AntiPatterns

Anti-patterns are the reverse of design patterns: they are common BAD solutions to problems. These dangerous pitfalls should be recognized and avoided.

Reference