Date post: | 07-Apr-2016 |
Category: |
Documents |
Upload: | andrei-olteanu |
View: | 17 times |
Download: | 1 times |
FROM STUPID TO SOLID CODE
March 28, 2015
FLORIN OLARIU
CENTRIC IT SOLUTION ROMANIA
ABOUT ME
• I’m working in field since 1996
• I’ve started as Java developer– I’m SCJP certified
• I’ve continued as team leader for a mixt team(Java/.NET
developers working with Waterfall methodologies)
• I’ve continued with .NET technologies since in 2003– I’m MCPD Windows Forms 2.0 certified – since 2006
– I’m MCPD Windows Forms 4.0 certified – since 2010
– I’m MCPD Web Forms 4.0 certified – since 2011
• Technical Lead/Scrum Master in Centric
March 28, 2015TITLE PRESENTATION
WHAT ABOUT?
Don't Be Stupid, Grasp Solid
March 28, 2015TITLE PRESENTATION
AGENDA
March 28, 2015TITLE PRESENTATION
STUPID CODE
March 28, 2015TITLE PRESENTATION
Stupid code, seriously?
STUPID CODE
• Singleton
• Tight coupling
• Untestability
• Premature optimization
• Indescriptive naming
• Duplication
March 28, 2015TITLE PRESENTATION
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
March 28, 2015TITLE PRESENTATION
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.
March 28, 2015TITLE PRESENTATION
UNTESTABILITY
• The unit tests should be easy
• Untestability is cause by tight coupling
March 28, 2015TITLE PRESENTATION
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.
March 28, 2015TITLE PRESENTATION
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
March 28, 2015TITLE PRESENTATION
DUPLICATION
• DRY – don’t repeat yourself
• KISS – keep it simple(stupid)
• Be lazy in the right way – write code only once.
March 28, 2015TITLE PRESENTATION
CODING KATA - INTRO
March 28, 2015TITLE PRESENTATION
CODING KATA - INTRO
March 28, 2015TITLE PRESENTATION
CODING KATA - INTRO
• KATA – came from martial arts
• Dave Thomas – has introduced Kata as learning technique
March 28, 2015TITLE PRESENTATION
DEMO - I
• Fibonacci – Kata TDD
March 28, 2015TITLE PRESENTATION
SOLID PRINCIPLES
• Single Responsibility Principle - SRP
• Open-Closed Principle - OCP
• Liskov Principle - LSP
• Interface Segregation Principle - ISP
• Dependency Inversion Principle - DIP
March 28, 2015TITLE PRESENTATION
JENGA GAME
March 28, 2015TITLE PRESENTATION
SOLID
March 28, 2015TITLE PRESENTATION
SINGLE RESPONSIBILITY PRINCIPLE
A class should have
only one reason to
change.
March 28, 2015TITLE PRESENTATION
SINGLE RESPONSIBILITY
March 28, 2015TITLE PRESENTATION
SINGLE RESPONSIBILITY - TIPS
• Split big classes
• Use layers
• Avoid god classes
• Write straightforward comments
March 28, 2015TITLE PRESENTATION
OPEN-CLOSED PRINCIPLE - OCP
Software entities
should be open for
extension and closed
for modification.
March 28, 2015TITLE PRESENTATION
OPEN-CLOSED PRINCIPLE
March 28, 2015TITLE PRESENTATION
OPEN-CLOSED PRINCIPLE - TIPS
• Make all members variables private
• No global variables
• Avoid setters (as much as possible)
March 28, 2015TITLE PRESENTATION
LISKOV SUBSTITUTION PRINCIPLE
March 28, 2015TITLE PRESENTATION
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.
March 28, 2015TITLE PRESENTATION
LISKOV SUBSTITUTION PRINCIPLE
March 28, 2015TITLE PRESENTATION
LISKOV SUBSTITUTION PRINCIPLE
March 28, 2015TITLE PRESENTATION
LISKOV SUBSTITUTION PRINCIPLE
March 28, 2015TITLE PRESENTATION
INTERFACE SEGREGATION PRINCIPLE
March 28, 2015TITLE PRESENTATION
INTERFACE SEGREGATION PRINCIPLE
•ISP states
that many client-
specific interfaces are
better than one general-
purpose interface.
March 28, 2015TITLE PRESENTATION
INTERFACE SEGREGATION PRINCIPLE
•You should not have to
implement methods that you
don't use. Enforcing ISP
gives you low coupling,
and high cohesion.
March 28, 2015TITLE PRESENTATION
DEPENDENCY INVERSION PRINCIPLE
March 28, 2015TITLE PRESENTATION
DEPENDENCY INVERSION PRINCIPLE
•DIP has 2 key points:
March 28, 2015TITLE PRESENTATION
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
March 28, 2015TITLE PRESENTATION
DEPENDENCY INVERSION PRINCIPLE
•Note•DIP is not the same like
Dependency Injection
March 28, 2015TITLE PRESENTATION
DEPENDENCY INVERSION PRINCIPLE
•Note•Dependency Injection is about
how one object knows about
another dependent object.
March 28, 2015TITLE PRESENTATION
DEPENDENCY INVERSION PRINCIPLE
•Note•In other words, it is about how
one object acquires a
dependency.
March 28, 2015TITLE PRESENTATION
DEPENDENCY INVERSION PRINCIPLE
•http://stackoverflow.com/questi
ons/6766056/dip-vs-di-vs-ioc
March 28, 2015TITLE PRESENTATION
ON MORE THING…
March 28, 2015TITLE PRESENTATION
SMILES
March 28, 2015TITLE PRESENTATION
SMILES
• Give a man a program, frustrate him for a day. Teach a man to
program frustrate him for a lifetime - Muhammad Waseem
March 28, 2015TITLE PRESENTATION
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?
March 28, 2015TITLE PRESENTATION
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.
March 28, 2015TITLE PRESENTATION
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 ….
March 28, 2015TITLE PRESENTATION
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.
March 28, 2015TITLE PRESENTATION
CONCLUSIONS
• Use your brain
• Writing SOLID code is not that hard
• Avoid STUPID code
March 28, 2015TITLE PRESENTATION
QUESTIONS?