Object Oriented Programming

3 Short Boring 

Talks

Instead of 

1 Long Boring 

Talk

1st Talk

DCI

Data Context and Interaction

  • Paradigm to program systems of communicating Objects.
  • Capturing the End User Model.
  • Decoupling what the system does (functionality) from what the system is (data model) .

Use case 1

Use case 2

All Methods

Issue ?

  • Source code does not reflect what happens at runtime.
  • Collaboration pattern of a use case is difficult to reason about.
  • Does not reflect how objects communicate at runtime to execute a use case.

Use case 1 DCI

Use case 2 DCI

What did we achieve ?

  • Separation of Stable Part (data) from the Dynamic Part (Use case).
  • Collaboration pattern among objects in one place.
  • Source code reflects how objects communicate at runtime.

Data

The data part of the DCI architecture is its (relatively) static data model with relations.

Context

The Context is the environment for which data objects execute their roles. 

Interaction

The interaction is "what the system does."

DCI MVC

Talk is cheap, Show me the Code.

- Linux Torvalds

2nd Talk

Sandi Metz 4 rules for OOP

Rules

  • Classes can be no longer than one hundred lines of code.
  • Methods can be no longer than five lines of code.
  • Pass no more than four parameters into a method. Hash options are parameters.
  • Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (facade pattern).

Rule 0 

You should break these rules only if you have a good reason or your pair lets you.

Show me the code

3rd Talk

Maybe

Monad

data Maybe t = Just t | Nothing

Maybe

  • nil is unfriendly and dangerous.
  • Maybe solves nil issues.
  • Concept inherited from languages like Haskell and Scala.
  • The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing).

Wrapped

  • Gem by Thoughtbot. (Mike Burns)
  • Simulates a Maybe Monad.
  • Wraps a value either with Some or None.
  • Unwrap the wrapped value explicitly in code.

Some code.

References

Thanks

Object Oriented Programming

By Rajeev Bharshetty

Object Oriented Programming

  • 1,582