European conference.

Slides:



Advertisements
Similar presentations
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
Advertisements

Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
Delegates & Events Observer and Strategy Patterns Game Design Experience Professor Jim Whitehead January 30, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Building SOLID Software with Dependency Injection Jeremy Rosenberg.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Company Confidential – Do Not Duplicate 2 Copyright 2008 McLane Advanced Technologies, LLC S.O.L.I.D. Software Development Achieving Object Oriented Principles,
Software Engineering. Administrivia This is me: Cyndi Rader You can reach me: Or find me here: BB 280D Class notes here:
Abstract Factory Design Pattern making abstract things.
Tech Talk Go4 Factory Patterns Presented By: Matt Wilson.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Inversion Of Control & Dependency Injection Break Apart The Dependencies Oren Eini Senior Developer We! Consulting Group
CSE 301 Exam Revision Lecture
Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.
S.O.L.I.D. Software Development 12 January 2010 (Martin Verboon, Patrick Kalkman, Stan Verdiesen)
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans.
Alternative Architectures: Inversion of Control Mike Hadlow mikehadlow.blogspot.com.
Refactoring & Testability. Testing in OOP programming No life in flexible methodologies and for refactoring- infected developers without SOME kind of.
Elements of OO Abstraction Encapsulation Modularity Hierarchy: Inheritance & Aggregation 4 major/essential elements3 minor/helpful elements Typing Concurrency.
Exceptions, cont’d. Factory Design Pattern COMP 401 Fall 2014 Lecture 12 9/30/2014.
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
Design for testability as a way to good coding Simone Chiaretta Architect, Council of the EU December 9 th,
Five design principles
Advanced Object-oriented Design Patterns Creational Design Patterns.
CS 325: Software Engineering March 19, 2015 Applying Patterns (Part B) Code Smells The Decorator Pattern The Observer Pattern The Template Method Pattern.
PRINCIPLES OF OBJECT ORIENTED DESIGN S.O.L.I.D. S.O.L.I.D Principles What is SOLID?  Acrostic of 5 Principles:  The Single Responsibility Principle.
SOLID Design Principles
Session 33 More on SOLID Steve Chenoweth Office: Moench Room F220 Phone: (812) Chandan Rupakheti Office: Moench.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Mantas Radzevičius ifm-2/2
Course information Old exam Resit Report Result and walkthrough
Architecture Patterns Design Patterns
Abstract Factory Pattern
Software Architecture & Difference from Design
How to be a Good Developer
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Interface Java 7 COMP T1.
Mark Seemann - Dependency Injection in .NET
Factory Patterns 1.
Software Design and Architecture
Singleton Pattern Command Pattern
Distribution and components
How to be a Good Developer
object oriented Principles of software design
Abstract Factory Pattern
Factory Method, Abstract Factory, and More
How to be a Good Developer
Intent (Thanks to Jim Fawcett for the slides)
Object Oriented Practices
AVG 24th 2015 ADVANCED c# - part 1.
Dependency Injection Joshua
Present by Andie Saizan, MCP
Java Programming Language
Code Smells 1.
11/29/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Advanced Java Programming
Object Oriented Practices
Introduction to Testing and Maintainable code
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Object Oriented Practices
Structural Patterns: Adapter and Bridge
CS 325: Software Engineering
Object Oriented Design & Analysis
Dependency Inversion principle
Dependency Injection Mechanism
GoF Patterns Ch. 26.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

european conference

How to decouple your code modules Dependency injection How to decouple your code modules

What is dependency injection? “Put appropriate instances in; don’t let the object create them.” Thanks for your atten… wait, wait, its “a bit” more complicated…

What is SOLID? S - Single responsibility principle (SRP) O - Open/closed principle (OCP) L - Liskov substitution principle (LSP) I - Interface segregation principle (ISP) D - Dependency inversion principle (DIP)

Single responsibility principle A class should only have one responsibility having problems finding a name is a sign of a violation creating things is a responsibility -> factory related to separation of concerns (SoC)

Dependency inversion principle Abstractions should not depend on details. Details should depend on abstractions "Code against interfaces (i.e. abstractions) not implementations (details)"

What is dependency injection "Dependency Injection is a 25-dollar term for a 5- cent concept." "Don't look for things - ask for them!" (Misko Hevery)

Why Dependency Injection? Decoupling of software pieces (classes) SRP flexibility composability exchangeability testability (mocking) maintainability

„To create or not to create“ Injectables and creatables – who is who? Example for creatables: All kinds of collections to store data or inner state (lists, dictionaries, TStrings, dynamic arrays, TStream) PODOs (aka data objects) – but sometimes not directly but with a factory depending on other requirements Injectables are those things that actually do something often called services

Reading suggestions

More material Not only purely on dependency injection but in general useful things about software design and architecture https://blog.ploeh.dk (Blog of Mark Seemann) http://misko.hevery.com/code-reviewers-guide/ (Guide to write testable code) https://www.youtube.com/playlist?list=PL693EFD059797C21E (Google Clean Code Talks)

Pure DI Learn and understand how DI works, what patterns and practices are helpful before using an automated way Try putting your dependencies together manually to get a feeling for how to design your classes and interfaces Once you‘ve written pages and pages of constructor calls, consider using a DI container

Service Locator DI is about passing things (to the constructor basically) Service Locator is about looking for things actively Code smell and dangerous anti-pattern Creates dependencies not only on the service locator but implicitly on types that need to be existing in the service locator Not easily noticable when creating a class but only when some method gets called

Composition root The point where DI starts – ideally there is only one and it‘s at the very start of the application When trying to fit DI into an existing application you might have multiple at first Move them closer to the start of the application and eventually they will converge

DI Container (finally!...) Factory pattern on steroids And a repository, and some other design patterns  A central place to register all your injectables and let them be created and composed automatically

Registering types RegisterType RegisterInstance Tell the container what implementing type is available and as what type it can resolve it Possibility to delegate the creation to another place than the container itself RegisterInstance Tell the container about an existing instance to let it participate in dependency injection

Registering types (advanced) RegisterFactory Register a type and let the container provide its implemention which then serves as factory to return instances returned by the container RegisterDecorator Register a type and let the container use it as decorator for other classes when it resolves them and automatically apply them

Controlling lifetimes New instance every time or use only one? Transient vs Singleton Possibility to control when new instances are being created or already created ones are returned Singleton, SingletonPerThread, PerResolve, Pooled

Type providers Possibility to extend the container to give it special knowledge about specific types and how to build them Examples of built-in providers are: LazyProvider, ListProvider, DynamicArrayProvider

Types of injection Constructor Injection Property Injection constructor parameters mandatory dependencies Property Injection properties/setter optional dependencies Null-Object pattern Field Injection Use only in exceptional cases – this is not possible with pure DI

Controlling the composition Types can be named All injection targets can be marked with the [Inject] attribute to control where and what is being injected Additional conditions can be applied to types and injection targets (planned)

Let‘s take a look at some example

Container.Free