Within this session you will learn and/or refresh the most important architectural design pattern and best practices to write better code. These patterns and practices build the foundation for writing maintainable application. More advances techniques like Inversion of Control and Dependency Injection are discussed in detail in the 2nd Clean Code presentation.
All 3 Clean Code presentations provide great value by themselves, but taken together are designed to offer a holistic approach to successful software creation. This first session creates the foundation for the 2nd Clean Code presentation on Dependency Injection, as it explains expected base knowledge.
Why writing Clean Code makes us more efficient
Over the lifetime of a product, maintaining the product is actually one - if not the most - expensive area(s) of the overall product costs. Writing clean code can significantly lower these costs. However, writing clean code also makes you more efficient during the initial development time and results in more stable code. You will be presented design patterns and best practices which will make you write better and more easily maintainable code, seeing code in a holistic way. You will learn how to apply them by using an existing implementation as the starting point of the presentation. Finally, patterns & practices benefits are explained.
This presentation is based on C# and Visual Studio 2010. However, the demonstrated patterns and practice can be applied to every other programming language too.
Top 10 Most Downloaded Games on Play Store in 2024
Â
Clean Code Part I - Design Patterns at SoCal Code Camp
1. SolCal
CodeCamp
Clean Code I
Design Patterns
and Best Practices
San Diego, June 24rd 2012
2. Theo Jungeblut
⢠Senior Software Developer at
AppDynamics in San Francisco
⢠architects decoupled solutions
tailored to business needs and crafts
maintainable code to last
⢠worked in healthcare and factory
automation, building mission critical
applications, framework &
platforms for 8+ years
⢠degree in Software Engineering
and Network Communications theo@designitright.net
⢠enjoys cycling, running and eating www.designitright.net
www.speakerrate.com/theoj
10. The âMust Readâ-Book(s)
by Robert C Martin
A Handbook of Agile
Software
Craftsmanship
âEven bad code can
function. But if code
isnât clean, it can bring a
development
organization to its
knees.â
13. Clean Code Developer â 1st Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
15. KISS-Principle â âKeep It Simple Stupidâ
by Kelly Johnson
http://blogs.smarter.com/blogs/Lego%20Brick.jpg
16. The Power of Simplicity
Graphic by Nathan Sawaya courtesy of brickartist.com
Graphic by Nathan Sawaya courtesy of brickartist.com
http://www.geekalerts.com/lego-iphone/
17. Chaos build from simplicity
Graphic by Nathan Sawaya courtesy of brickartist.com
19. Donât repeat yourself (DRY)
by Andy Hunt and Dave Thomas in their book âThe Pragmatic Programmerâ
// Code Copy and Paste Method // DRY Method
public Class Person public Class Person
{ {
public string FirstName { get; set;} public string FirstName { get; set;}
public string LastName { get; set;} public string LastName { get; set;}
public Person(Person person) public Person(Person person)
{ {
this.FirstName = string.IsNullOrEmpty(person.FirstName) this.FirstName = person.FirstName.CloneSecured();
? string.Empty : (string) person.FirstName.Clone(); this.LastName = person.LastName.CloneSecured();
}
this.LastName = string.IsNullOrEmpty(person.LastName)
? string.Empty : (string) person.LastName.Clone(); public object Clone()
} {
return new Person(this);
public object Clone() }
{ }
return new Person(this);
}
} public static class StringExtension
{
public static string CloneSecured(this string original)
{
return string.IsNullOrEmpty(original) ? string.Empty : (string)original.Clone();
}
}
20. Clean Code Developer â 1st Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
21. Clean Code Developer â 2nd Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
25. Class, Struct, Enum etc.
http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
26. Separation of Concerns (SoC)
probably by Edsger W. Dijkstra in 1974
⢠âIn computer science,
separation of concerns (SoC) is
the process of separating a
computer program into distinct
features that overlap in
functionality as little as possible.
â˘A concern is any piece of
interest or focus in a program.
Typically, concerns are
synonymous with features or
behaviors. â
http://en.wikipedia.org/wiki/Separati
on_of_Concerns
27. Single Responsibility Principle (SRP)
by Robert C Martin
âEvery object should have a single responsibility, and that
responsibility should be entirely encapsulated by the class.â
http://en.wikipedia.org/wiki/Single_responsibility_principle
public class Logger : ILogger
{
public Logger(ILoggingSink loggingSink)
{}
public void Log(string message)
{}
}
http://www.ericalbrecht.com
29. Clean Code Developer â 2nd Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
30. SolCal
CodeCamp
Clean Code III
Software
Craftsmanship
San Diego, June 23rd 2012
31. Clean Code Developer â 3rd Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
33. Information Hiding Principle (IHP)
by David Parnas (1972)
â.. information hiding is the principle of
segregation of the design decisions on a
computer program that are most likely to
change, ..â
http://en.wikipedia.org/wiki/Information_hiding
34. Interfaces / Contracts
⢠Decouple Usage and Implementation through introduction of a contract
⢠Allows to replace implementation without changing the consumer
public interface ILogger public class Logger : ILogger
{ {
void Log(string message); public Logger(ILoggingSink loggingSink)
} {}
public void Log(string message)
{}
}
36. Liskov Substitution Principle (LSP)
by Barbara Liskov, Jannette Wing (1994)
âLiskovâs notion of a behavioral subtype
defines a notion of substitutability for
mutable objectsâ
http://en.wikipedia.org/wiki/Liskov_substitution_principle
38. Dependency Inversion Principle (DIP)
by Robert C. Martin
⢠âHigh-level modules should not depend on
low-level modules. Both should depend on
abstractions.
⢠Abstractions should not depend upon details.
Details should depend upon abstractions.â
http://en.wikipedia.org/wiki/Dependency_inversion_principle
39. Clean Code Developer â 3rd Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
40. Clean Code Developer â 4th Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
42. Open/Closed Principle (OCP)
by Bertrand Meyer (1988)
An implementation is open for extension
but closed for modification
http://en.wikipedia.org/wiki/Open/closed_principle
44. Law of Demeter (LoD)
Northeastern University (1987)
â
⢠Each unit should have only limited knowledge
about other units: only units âcloselyâ related
to the current unit.
⢠Each unit should only talk to its friends;
donât talk to strangers
⢠Only talk to your immediate friends.â
http://en.wikipedia.org/wiki/Law_Of_Demeter
45. S Single Responsibility Principle
O Open/Closed Principle
L Liskov Substitution Principle
I Interface Segregation Principle
D Dependency Inversion Principle
Robert C Martin: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
46. Clean Code Developer â 4th Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
47. Silicon Valley Code Camp Oct. 6th â 7th
http://www.siliconvalley-codecamp.com
48. Clean Code Developer â 5th Iteration
by Ralf Westphal & Stefan Lieser â http://www.clean-code-developer.de
Graphic by Michael HĂśnnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
49. Summary Clean Code
Maintainability is achieved through:
⢠Readability (Coding Guidelines)
⢠Simplification and Specialization
(KISS, SoC, SRP, OCP, )
⢠Decoupling (LSP, DIP, IHP, Contracts,
LoD, CoP, IoC or SOA)
⢠Avoiding Code Bloat (DRY, YAGNI)
⢠Quality through Testability
(all of them!)
50. Q&A
Downloads,
Feedback & Comments:
theo@designitright.net
www.designitright.net
www.speakerrate.com/theoj
Graphic by Nathan Sawaya courtesy of brickartist.com