object calisthenics; practices for writing object-oriented c#

17
#comdaybe Object Calisthenics Practices for Writing Object-Oriented Aviva Solutions Dennis Doomen

Upload: dennis-doomen

Post on 18-Dec-2014

1.277 views

Category:

Technology


4 download

DESCRIPTION

According to Wikipedia, Calisthenics are a form of exercise consisting of a variety of simple, often rhythmical, movements, generally without using equipment or apparatus. Since programming without Visual Studio is going to be a bit challenging you can define Object Calisthenics as a programming exercise that uses simple rules to motivate you to take an object-oriented approach to programming. As an experienced developer practicing Test Driven Development I was a bit sceptical of whether I really needed those rules to be a better programmer. But to my surprise those little rules really reinforced my beliefs about building high-quality software using the principles of object-orientation, SOLID and Clean Code. So what are those rules? I won’t tell you…yet. Just come to my session and I’ll let you in on my secrets….

TRANSCRIPT

Page 1: Object Calisthenics; Practices for Writing Object-Oriented C#

#comdaybe

Object CalisthenicsPractices for Writing Object-Oriented

Aviva SolutionsDennis Doomen

Page 2: Object Calisthenics; Practices for Writing Object-Oriented C#

Object…what?

Object Calisthenics

Object..\ˌka-ləs-ˈthe-niks\

Page 3: Object Calisthenics; Practices for Writing Object-Oriented C#

Like this?

Page 4: Object Calisthenics; Practices for Writing Object-Oriented C#

“…9 rules of thumb that will help push your code into good object-oriented shape...”Jeff Bay

Page 5: Object Calisthenics; Practices for Writing Object-Oriented C#

So who am I?

Principal ConsultantAviva Solutions

Fluent Assertions

C# Coding Guidelines

@ddoomen

TDD, DDD, BDD

Application Lifecycle Management

Agile

XP

www.dennisdoomen.net

Page 6: Object Calisthenics; Practices for Writing Object-Oriented C#

demo

One level of indentation per methodRule 1

Page 7: Object Calisthenics; Practices for Writing Object-Oriented C#

demo

One dot per lineDon’t use the else keyword

Rules 2 & 5

Page 8: Object Calisthenics; Practices for Writing Object-Oriented C#

demo

Wrap all primitives and strings…a.k.a. first-class types

Rule 3

Page 9: Object Calisthenics; Practices for Writing Object-Oriented C#

demo

First-class collectionsRule 4

Page 10: Object Calisthenics; Practices for Writing Object-Oriented C#

Choose names carefully…not too short

…and…not too long…contextual

Rule 6

Page 11: Object Calisthenics; Practices for Writing Object-Oriented C#

Keep all classes small…a.k.a. Single Responsibility

Principle

Rule 7

Page 12: Object Calisthenics; Practices for Writing Object-Oriented C#

No more than two instance variablesRule 8

Page 13: Object Calisthenics; Practices for Writing Object-Oriented C#

demo

No propertiesRule 9

Page 14: Object Calisthenics; Practices for Writing Object-Oriented C#

demo

…no protected properties…test data builders…more refactoring

Final result

Page 15: Object Calisthenics; Practices for Writing Object-Oriented C#

Q&A

Page 16: Object Calisthenics; Practices for Writing Object-Oriented C#

Resources

• Example Code (original by Johan Martinsson)

• Object Calisthenics (by Jeff Bay)• C# Coding Guidelines (by me)• www.dennisdoomen.net (by me…

again )• Agile Principles, Patterns, and Practic

es in C# (by Uncle Bob)

Page 17: Object Calisthenics; Practices for Writing Object-Oriented C#

Thank you!Object Calisthenatics