Sei sulla pagina 1di 50

FROM STUPID TO SOLID CODE

FLORIN OLARIU
CENTRIC IT SOLUTION ROMANIA
March 28, 2015

ABOUT ME

Im working in field since 1996


Ive started as Java developer
Im SCJP certified

Ive continued as team leader for a mixt team(Java/.NET


developers working with Waterfall methodologies)
Ive continued with .NET technologies since in 2003
Im MCPD Windows Forms 2.0 certified since 2006
Im MCPD Windows Forms 4.0 certified since 2010
Im MCPD Web Forms 4.0 certified since 2011

Technical Lead/Scrum Master in Centric

TITLE PRESENTATION

March 28, 2015

WHAT ABOUT?

Don't Be Stupid, Grasp Solid

TITLE PRESENTATION

March 28, 2015

AGENDA

TITLE PRESENTATION

March 28, 2015

STUPID CODE

Stupid code, seriously?

TITLE PRESENTATION

March 28, 2015

STUPID CODE

Singleton
Tight coupling
Untestability
Premature optimization
Indescriptive naming
Duplication

TITLE PRESENTATION

March 28, 2015

SINGLETON

The most well-known pattern used


Program using global state are very difficult to test
Program that rely on global state hide their dependencies

TITLE PRESENTATION

March 28, 2015

TIGHT COUPLING

Aka : strong coupling


The main goal is to reduce coupling between modules
Difficult to reuse
Hard to test

Coupling - the degree to which each program module relies


on each one of the other modules.

TITLE PRESENTATION

March 28, 2015

UNTESTABILITY

The unit tests should be easy


Untestability is cause by tight coupling

TITLE PRESENTATION

March 28, 2015

PREMATURE OPTIMIZATION

Donald Knuth said: premature optimization is the root of all


evil. There is only cost, and no benefit.
Two rules to optimize an application:
don't do it;
(for experts only!) don't do it yet.

TITLE PRESENTATION

March 28, 2015

INDESCRIPTIVE NAMING

Programming languages are for humans.


Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.
Martin Fowler

TITLE PRESENTATION

March 28, 2015

DUPLICATION

DRY dont repeat yourself


KISS keep it simple(stupid)

Be lazy in the right way write code only once.

TITLE PRESENTATION

March 28, 2015

CODING KATA - INTRO

TITLE PRESENTATION

March 28, 2015

CODING KATA - INTRO

TITLE PRESENTATION

March 28, 2015

CODING KATA - INTRO

KATA came from martial arts


Dave Thomas has introduced Kata as learning technique

TITLE PRESENTATION

March 28, 2015

DEMO - I

Fibonacci Kata TDD

TITLE PRESENTATION

March 28, 2015

SOLID PRINCIPLES

Single Responsibility Principle - SRP


Open-Closed Principle - OCP
Liskov Principle - LSP
Interface Segregation Principle - ISP
Dependency Inversion Principle - DIP

TITLE PRESENTATION

March 28, 2015

JENGA GAME

TITLE PRESENTATION

March 28, 2015

SOLID

TITLE PRESENTATION

March 28, 2015

SINGLE RESPONSIBILITY PRINCIPLE

A class should have


only one reason to
change.
TITLE PRESENTATION

March 28, 2015

SINGLE RESPONSIBILITY

TITLE PRESENTATION

March 28, 2015

SINGLE RESPONSIBILITY - TIPS

Split big classes


Use layers
Avoid god classes
Write straightforward comments

TITLE PRESENTATION

March 28, 2015

OPEN-CLOSED PRINCIPLE - OCP

Software entities
should be open for
extension and closed
for modification.
TITLE PRESENTATION

March 28, 2015

OPEN-CLOSED PRINCIPLE

TITLE PRESENTATION

March 28, 2015

OPEN-CLOSED PRINCIPLE - TIPS

Make all members variables private


No global variables
Avoid setters (as much as possible)

TITLE PRESENTATION

March 28, 2015

LISKOV SUBSTITUTION PRINCIPLE

TITLE PRESENTATION

March 28, 2015

LISKOV SUBSTITUTION PRINCIPLE

LSP states that objects in a


program should
be replaceable with
instances of their subtypes
without altering the
correctness of the program.
TITLE PRESENTATION

March 28, 2015

LISKOV SUBSTITUTION PRINCIPLE

TITLE PRESENTATION

March 28, 2015

LISKOV SUBSTITUTION PRINCIPLE

TITLE PRESENTATION

March 28, 2015

LISKOV SUBSTITUTION PRINCIPLE

TITLE PRESENTATION

March 28, 2015

INTERFACE SEGREGATION PRINCIPLE

TITLE PRESENTATION

March 28, 2015

INTERFACE SEGREGATION PRINCIPLE

ISP states
that many clientspecific interfaces are
better than one generalpurpose interface.
TITLE PRESENTATION

March 28, 2015

INTERFACE SEGREGATION PRINCIPLE

You should not have to


implement methods that you
don't use. Enforcing ISP
gives you low coupling,
and high cohesion.
TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

DIP has 2 key points:

TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

DIP has 2 key points:

Abstractions should not depend upon


details both should depend on
abstractions
Details should not depend upon
abstraction details should depend
on abstractions

TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

Note

DIP is not the same like


Dependency Injection

TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

Note

Dependency Injection is about


how one object knows about
another dependent object.

TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

Note

In other words, it is about how


one object acquires a
dependency.

TITLE PRESENTATION

March 28, 2015

DEPENDENCY INVERSION PRINCIPLE

http://stackoverflow.com/questi
ons/6766056/dip-vs-di-vs-ioc

TITLE PRESENTATION

March 28, 2015

ON MORE THING

TITLE PRESENTATION

March 28, 2015

SMILES

TITLE PRESENTATION

March 28, 2015

SMILES

Give a man a program, frustrate him for a day. Teach a man to


program frustrate him for a lifetime - Muhammad Waseem

TITLE PRESENTATION

March 28, 2015

SMILES

Give a man a program, frustrate him for a day. Teach a man to


program frustrate him for a lifetime - Muhammad Waseem
What is the object-oriented way of getting rich?

TITLE PRESENTATION

March 28, 2015

SMILES

Give a man a program, frustrate him for a day. Teach a man to


program frustrate him for a lifetime - Muhammad Waseem
What is the object-oriented was of getting rich? Inheritance of
course.

TITLE PRESENTATION

March 28, 2015

SMILES

Give a man a program, frustrate him for a day. Teach a man to


program frustrate him for a lifetime - Muhammad Waseem
What is the object-oriented was of getting rich? Inheritance of
course.
Walking on water and developing software to specification are
easy .

TITLE PRESENTATION

March 28, 2015

SMILES

Give a man a program, frustrate him for a day. Teach a man to


program frustrate him for a lifetime - Muhammad Waseem
What is the object-oriented was of getting rich? Inheritance of
course.
Walking on water and developing software to specification are
easy as long as both are frozen.

TITLE PRESENTATION

March 28, 2015

CONCLUSIONS

Use your brain


Writing SOLID code is not that hard
Avoid STUPID code

TITLE PRESENTATION

March 28, 2015

QUESTIONS?

THANK YOU!

florin.olariu@centric.eu

FLORIN OLARIU
March 28, 2015

Potrebbero piacerti anche