How To 

Think 

Like a 

Programmer

Part 4: Design Patterns
By @ErikRalston

Design Pattern


A reusable concept for structuring code

A writing "cliche" for code





Programming Paradigm

Procedural Programming


Code and Data are Separate

Code is broken into functions

Code is pages (files) of paragraphs (functions)

Object-oriented Programming


Code and Data Organized Together


Code becomes characters with defined abilities (Object)
Or each Object could be thought of as its own book


Principles of oOp


Encapsulation

Bundling of data with behavior, exposing only necessary data

Abstraction

Simplify the program by hiding state

Inheritance

Reuse functionality by

oo style #1: classes


Each object is a Type of object
They belong to a "Class"

Traits are genetic

Types can have child types that "inherit" their abilities

C++, Java, C#

OO Style #2: prototypes


Each object refers to a parent "Prototype" object
Anything requested by 

Traits are Contextual

JavaScript





object-oriented

design patterns

Strategy pattern


Implement a different algorithms for related problems
Each in  different sub-class

Singleton Pattern


Maintain only a single instance of an object

Grants access across the program to a necessary resource


factory Pattern


Instead of objects making themselves
Have an object make one for you

command pattern


Make an object for each action with a system

Enables extension of the system without altering it

Visitor Pattern


For a collection of objects
Place logic in something that visits them 
Instead of the collection itself

Singleton Pattern


Maintain only a single instance of an object

Composite Pattern


Make a sub-class that is a collection of the class
Applying actions to all children


hands-On


Designing Photoshop

How to Think Like a Programmer: Design Patterns

By Erik Ralston

How to Think Like a Programmer: Design Patterns

Part 4, writing cliches of programmers and how to use them to communicate with your team and simplify your life - INCOMPLETE

  • 1,081