33
Advanced OOP Advanced OOP Laws Laws Principles Principles Idioms Idioms Clint Edmonson Clint Edmonson

Advanced OOP - Laws, Principles, Idioms

Embed Size (px)

DESCRIPTION

Ever heard of the Law of Demeter? How about the Liskov Substitution Principle? This talk introduces key object-oriented laws and principles currently used in our field and provides guidance for their use when building applications on the .NET platform.

Citation preview

Page 1: Advanced OOP - Laws, Principles, Idioms

Advanced OOPAdvanced OOPLawsLaws Principles Principles IdiomsIdioms

Clint EdmonsonClint Edmonson

Advanced OOPAdvanced OOPLawsLaws Principles Principles IdiomsIdioms

Clint EdmonsonClint Edmonson

Page 2: Advanced OOP - Laws, Principles, Idioms

what is oop?what is oop?

Page 3: Advanced OOP - Laws, Principles, Idioms

abstractionabstractionencapsulationencapsulation

inheritanceinheritance

polymorphismpolymorphism

Page 4: Advanced OOP - Laws, Principles, Idioms

structuralstructural

Page 5: Advanced OOP - Laws, Principles, Idioms

domain driven designdomain driven design

All software can be composed of only four elements:

- Value objects - Entities- Services- Modules

Page 6: Advanced OOP - Laws, Principles, Idioms

separation of concernsseparation of concerns

Every class and method should have a single responsibility.

All its functionality should be narrowly aligned with that responsibility.

Page 7: Advanced OOP - Laws, Principles, Idioms

the DRY principle

Don’t repeat yourself.Don’t repeat yourself.Don’t repeat yourself.

Page 8: Advanced OOP - Laws, Principles, Idioms

theory of one right placetheory of one right place

There should be only one right place for a piece of nontrivial of code,

and one right place to make a likely maintenance change.

Page 9: Advanced OOP - Laws, Principles, Idioms

unit of workunit of workDefine entity families around transactional boundaries.

Page 10: Advanced OOP - Laws, Principles, Idioms

the open-closed principlethe open-closed principle

Software entities (classes, methods, and modules) should be

open for extension

but closed for modification.

Page 11: Advanced OOP - Laws, Principles, Idioms

design by contractFortify your methods through

preconditions, post-conditions, and invariant assertions.

Page 12: Advanced OOP - Laws, Principles, Idioms

creationalcreational

Page 13: Advanced OOP - Laws, Principles, Idioms

declarative programming

Use attributes to describe what you want to happen and leverage a framework will take care of the how.

Page 14: Advanced OOP - Laws, Principles, Idioms

the provider modelthe provider model

Define a public service façade that uses an private implementation to perform all of it’s work.

Page 15: Advanced OOP - Laws, Principles, Idioms

inversion of controlinversion of control

Leverage configuration files to automatically create objects as they are needed.

Page 16: Advanced OOP - Laws, Principles, Idioms

dependency injectiondependency injection

Declaratively describe dependencies between classes and an IOC framework can automatically instantiate all of them.

Page 17: Advanced OOP - Laws, Principles, Idioms

object:relational mappingobject:relational mapping

Leverage IOC and dependency injection to automatically load entities from your database.

Page 18: Advanced OOP - Laws, Principles, Idioms

behavioralbehavioral

Page 19: Advanced OOP - Laws, Principles, Idioms

principle of scenario driven designprinciple of scenario driven design

All functionality should be driven by usage scenarios.

Page 20: Advanced OOP - Laws, Principles, Idioms

occam’s razoroccam’s razor

The simplest solution is usually the best.

Page 21: Advanced OOP - Laws, Principles, Idioms

the pareto principlethe pareto principle

For many phenomena, 80% of the consequences stem from 20% of the causes

Page 22: Advanced OOP - Laws, Principles, Idioms

the law of demeterthe law of demeter“Don’t talk to your neighbor’s neighbor!”

An object should only call methods and properties belonging to:

- Itself- Any parameters passed in- Objects it creates- Child components

Page 23: Advanced OOP - Laws, Principles, Idioms

principle of least resource usage

principle of least resource usage

The minimal amount of computational resources should be used to solve a particular need.

Page 24: Advanced OOP - Laws, Principles, Idioms

principle of least privilegeprinciple of least privilege

Provide the minimal level of access necessary for consumers to do their job.

Combined with the previous principle…

Classes and methods should be as static and private as possible.

Page 25: Advanced OOP - Laws, Principles, Idioms

the liskov substitution principlethe liskov substitution principle

A derived class should be completely and transparently substitutable for it’s base class.

Page 26: Advanced OOP - Laws, Principles, Idioms

idempotentsidempotents

Transactional systems should allow thesame information to be received multiple times without being reprocessed.

Page 27: Advanced OOP - Laws, Principles, Idioms

cyclomatic complexitycyclomatic complexity

The depth of nested logic should be kept to a minimum.

Page 28: Advanced OOP - Laws, Principles, Idioms

What are What are youryour principles?principles?What are What are youryour principles?principles?

Page 29: Advanced OOP - Laws, Principles, Idioms
Page 30: Advanced OOP - Laws, Principles, Idioms
Page 31: Advanced OOP - Laws, Principles, Idioms

Books– Code Complete - McConnell– Effective C# - Wagner– Framework Design Guidelines – Cwalina & Abrams– Writing Solid Code - Maguire

Links– Application Architecture for .NET– OO Design Principles– Principles of Object Oriented Design– Separation of Concerns (Wikipedia)

References

Page 32: Advanced OOP - Laws, Principles, Idioms

Clint Edmonson

[email protected]

http://www.notsotrivial.net

Page 33: Advanced OOP - Laws, Principles, Idioms

© 2008 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this information.