MVC
Model-View-Controller
 meta design pattern
Clean coding

•   Data and function encapsulation

•   SRP

•   DRY

•   Favor composition over inheritance

•   Use design patterns

•   Program to interfaces (not implementation)

•   Don’t code for now, but for the future
Data encapsulation


•   Why ? Ensure data integrity

•   Why ? Conceal implementation

•   How ? Limit data access points

•   How ? Control data access points: use functions
    and getters/setters
Single Responsibility Principle
•   What ? Each class should have only one
    responsibility, no exceptions.

•   Why ? More responsibilities muddy intent,
    scalability and reusability.

•   How ? Explain what your class does in max 10
    words, w/o using ‘and’ and ‘or’.

•   How ? Separate responsibilities into different
    classes

•   Example:
    https://gist.github.com/e05e8483bdde9743df0c
Don’t Repeat Yourself

•   What ? Reduce repetition and redundancy of data
    and functionality

•   Why ? System changes will require a single
    modification entry

•   Why ? Modifications don’t have to be “synced” in
    the various actors of the system

•   How ? Functions, classes, inheritance, composition,
    factory patterns
Composition > Inheritance

•   What ? If a class can be used instead of inherited,
    favor usage.

•   Why ? With “bad” inheritance you need to know
    the implementation details of the super class ->
    breaks encapsulation

•   Why ? Inheritance complicates class relationships

•   Why ? Inheritance introduces functionality
    cascading and data integrity strain

•   Why ? Inheritance makes it a lot harder to have a
    good birds-eye view of your classes.
Design patterns


•   What ? Solutions to common programming
    problems

•   Why ? You’re lazy, right?

•   How ? http://www.oodesign.com/

•   Example:
    https://gist.github.com/4f666ecf1ffe5f9ec36c
Interfaces

•   What ? A contract

•   Why ? Allows for polymorphism

•   Example:
    https://gist.github.com/ab481aa9846a8b401026

•   Why ? Forces you to define an actor’s boundaries
    and means of communication

•   Why ? Sets up the API
Don’t code for now
          but for the future
•   What ? Don’t program to “get things done”,
    program to “keep on getting things done”

•   Why ? SRM: Scale, Reuse, Maintain

•   Why ? Use cases changes (those fucking clients!),
    technologies change, clients want you to expand;
    not start anew, you want to rob your previous
    projects to “get new things done”

•   How ? see previous slides
Traditional MVC

•   What ? “Meta” or architectural design pattern

•   Why ? Allows for swapping implementations

•   Model: data (state)

•   View: presentation of the data

•   Controller: accepts user input and controls model
    and view

•   http://goo.gl/1wzWR
Mediated MVC



•   Controller: acts as a mediator between view and
    model

•   http://goo.gl/eH1qC
Thanks
                       slides:
http://www.slideshare.net/creynders/mvc-10323083
                       code:
    https://github.com/creynders/MVC-Example
                     questions:
                  @camillereynders

Mvc

  • 1.
  • 2.
    Clean coding • Data and function encapsulation • SRP • DRY • Favor composition over inheritance • Use design patterns • Program to interfaces (not implementation) • Don’t code for now, but for the future
  • 3.
    Data encapsulation • Why ? Ensure data integrity • Why ? Conceal implementation • How ? Limit data access points • How ? Control data access points: use functions and getters/setters
  • 4.
    Single Responsibility Principle • What ? Each class should have only one responsibility, no exceptions. • Why ? More responsibilities muddy intent, scalability and reusability. • How ? Explain what your class does in max 10 words, w/o using ‘and’ and ‘or’. • How ? Separate responsibilities into different classes • Example: https://gist.github.com/e05e8483bdde9743df0c
  • 5.
    Don’t Repeat Yourself • What ? Reduce repetition and redundancy of data and functionality • Why ? System changes will require a single modification entry • Why ? Modifications don’t have to be “synced” in the various actors of the system • How ? Functions, classes, inheritance, composition, factory patterns
  • 6.
    Composition > Inheritance • What ? If a class can be used instead of inherited, favor usage. • Why ? With “bad” inheritance you need to know the implementation details of the super class -> breaks encapsulation • Why ? Inheritance complicates class relationships • Why ? Inheritance introduces functionality cascading and data integrity strain • Why ? Inheritance makes it a lot harder to have a good birds-eye view of your classes.
  • 7.
    Design patterns • What ? Solutions to common programming problems • Why ? You’re lazy, right? • How ? http://www.oodesign.com/ • Example: https://gist.github.com/4f666ecf1ffe5f9ec36c
  • 8.
    Interfaces • What ? A contract • Why ? Allows for polymorphism • Example: https://gist.github.com/ab481aa9846a8b401026 • Why ? Forces you to define an actor’s boundaries and means of communication • Why ? Sets up the API
  • 9.
    Don’t code fornow but for the future • What ? Don’t program to “get things done”, program to “keep on getting things done” • Why ? SRM: Scale, Reuse, Maintain • Why ? Use cases changes (those fucking clients!), technologies change, clients want you to expand; not start anew, you want to rob your previous projects to “get new things done” • How ? see previous slides
  • 10.
    Traditional MVC • What ? “Meta” or architectural design pattern • Why ? Allows for swapping implementations • Model: data (state) • View: presentation of the data • Controller: accepts user input and controls model and view • http://goo.gl/1wzWR
  • 11.
    Mediated MVC • Controller: acts as a mediator between view and model • http://goo.gl/eH1qC
  • 12.
    Thanks slides: http://www.slideshare.net/creynders/mvc-10323083 code: https://github.com/creynders/MVC-Example questions: @camillereynders

Editor's Notes