Architecture Patterns Design Patterns

Slides:



Advertisements
Similar presentations
Systems Architecture Use Case Diagram, System Overview, Class Diagram Design Patterns (weve used) Refactorings (weve used) Table of Contents.
Advertisements

Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Factory Design Pattern, cont’d COMP 401 Fall 2014 Lecture 13 10/2/2014.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Structure of a web application1 Dr Jim Briggs. MVC Structure of a web application2.
7/16/2015Singleton creational design pattern1 Eivind J. Nordby Karlstad University Dept. of Computer Science.
State,identity and behavior of objects Sem III K.I.R.A.S.
Design Patterns.
Todd Snyder Development Team Lead Infragistics Experience Design Group.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Creational Patterns (1) CS350, SE310, Fall, 2010.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
1 Mapping to Relational Databases Presented by Ramona Su.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Programming in Java CSCI-2220 Object Oriented Programming.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
Abstract Factory and Factory Method CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Introduction to Object-Oriented Programming Lesson 2.
CS 325: Software Engineering March 19, 2015 Applying Patterns (Part B) Code Smells The Decorator Pattern The Observer Pattern The Template Method Pattern.
Refactoring1 Improving the structure of existing code.
Dependency Inversion By Steve Faurie. Dependency Inversion Described in Agile Principles, Patterns and Practices in C# by Robert C. Martin.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Patterns in programming
What is Agile Design? SRP OCP LSP DIP ISP
Design Patterns: MORE Examples
Refactoring Architecture Patterns Design Patterns
Unit II-Chapter No. : 5- design Patterns
Structure of a web application
Architecture Patterns and Refactoring
GUI and systems Presentation and models Views and presentation logic
Chapter 10 Design Patterns.
EKT 472: Object Oriented Programming
Creational Pattern: Prototype
Software Design and Architecture
Design Patterns with C# (and Food!)
Object-Oriented Principles and Implementations
Intent (Thanks to Jim Fawcett for the slides)
Chapter 6: Using Design Patterns
Design Patterns in Operating Systems
Advanced Programming Behnam Hatami Fall 2017.
More inheritance, Abstract Classes and Interfaces
Object Oriented Design Patterns - Creational Patterns
Chapter 20 Object-Oriented Analysis and Design
Singleton Pattern Pattern Name: Singleton Pattern Context
CS 350 – Software Design Singleton – Chapter 21
Fundaments of Game Design
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Abstract Classes and Interfaces
CS 325: Software Engineering
Designing For Testability
European conference.
Abstract Classes and Interfaces
GoF Patterns Ch. 26.
Presentation transcript:

Architecture Patterns Design Patterns Architectures 2 Architecture Patterns Design Patterns

Layer Supertype Some functionality is frequently common for all classes In a module or layer Separated out in a ”layer supertype” Domain layer Data mapper ”layer”

Testing and Speed Considerations Not all tests need real DB Some test domain Some test mapper Some test DB access When focus is not db A fake db will do Replace data mapper with one using in-memory data Mappers need same interface Apply DIP Request Data Mapper Presentation Logic Use Create/Read Object-oriented Domain Model Access Data Source Logic

What We Have We have two setups with mapper classes Each with its own layer supertype

What we Need The mappers should be interchangeable, so we need something like this The DB client should not bother whether it gets a Linq, SQL or Dummy The RoomMapper interface needs to be the same The client depends on an interface, not on a particular mapper DIP with dynamic replacement of the actual mapper possible

Arrange Mappers According to Domain Classes What the client is concerned about To get a room mapper, a person mapper, a booking mapper Not interested in whether it is linq, sql or dummy Need an orthogonal structure One mapper from each technology need to implement RoomMapper, PersonMapper etc ISP: Treat classes according to their roles (interfaces)

Where the Mapper Comes From The client can get its mapper in two different ways Have it given to itself from the outside: Dependency Injection Ask someone for it We may let it ask for it Depending on setups, we may want to have different setups LinqBookingMapper, LinqRoomMapper, LinqPersonMapper DummyBookingMapper, DummyRoomMapper, DummyPersonMapper But not LinqBookingMapper, DummyRoomMapper, SqlPersonMapper The setup needs to be consistent

Solution: Abstract Factory Use design pattern Abstract Factory One factory delivers a consistent set of mappers

Applying Patterns Refactoring Architecture Patterns Design Patterns Singleton Abstract Factory XP: eXtreme Programming, Kent Beck et al DSDM: Dynamic System Development Method, DSDM Consortium, UK Crystal: Crystal Clear and other Crystal methods by Alistair Cockburn Evo: Evolutionary development, Tom Gilb FDD: Feature Driven Development, Jeff De Luca Lean: Lean Software Development, Mary and Tom Poppendieck 9

Where The Factory Comes From: Singleton With different factories, one is the current one Assign that one to a singleton Similar to a global variable MapperFactory.Instance returns the current factory Every time you need a new room mapper roomMapper = MapperFactory.Instance.MakeRoomMapper(); The factory singleton manages a current instance in terms of MapperFactory That is an abstract class We need to inject an instance of a concrete class into the singleton MapperFactory.SetFactory(new LinqMapperFactory());

The Singleton namespace DataMappers { abstract public class MapperFactory private static MapperFactory instance; public static void SetFactory(MapperFactory factory) instance = factory; } public static MapperFactory Instance get { return instance; } abstract public RoomMapper MakeRoomMapper(); abstract public PersonMapper MakePersonMapper(); abstract public BookingMapper MakeBookingMapper();

Subclasses Implement the Factory Methods using DataMappers; namespace LinqDataMappers { public class LinqMapperFactory : MapperFactory public override RoomMapper MakeRoomMapper() return new LinqRoomMapper(); } public override PersonMapper MakePersonMapper() return new LinqPersonMapper(); public override BookingMapper MakeBookingMapper() return new LinqBookingMapper();

The Factory Hierarchy The Instance is typed MapperFactory So it may return any of the subclasses It needs to be instantiated See demo Principle: LSP The clients will not notice any difference

The Complete Mapper Solution …

Using the Mappers Now we know how to create and manage mappers in a consistent way Through an Abstract Factory The application still needs to get hold of a mapper to read and save data The abstract superclass Mapper may act as a mapper holder A Singleton-like property for each mapper Mapper.BookingMapper.GetAll() A method to clear the current mapper of each kind Called at the end of a user transaction Needed in order to reset the Identity Map Which is needed to avoid duplicate in-memory objects Mapper.ClearBookingMapper() A method to clear all the current mappers Mapper.ClearMappers()

Implementing the Mapper Access Mechanisms A singleton-like static accessor property in abstract class Mapper private static BookingMapper bookingMapper; public static BookingMapper BookingMapper { get { if (bookingMapper == null) bookingMapper = MapperFactory.Instance.MakeBookingMapper(); return bookingMapper; } } Resetting a mapper public static void ClearBookingMapper() {bookingMapper = null;} Resetting all the mappers public static void ClearMappers() {ClearRoomMapper(); ClearPersonMapper(); ClearBookingMapper();}

Consequences of Mapper and Identity Map Clients may use the BookingMapper etc properties directly Mapper.BookingMapper always gives a (new or old) booking mapper Call ClearMappers() when done with a user transaction That is after the last update of the user transaction Or when starting a new one with fresh data When you know that you are done with your domain objects Resets the identity map in the mapper Assures that reading the same record several times does not result in several copies of the corresponding domain object in memory Triggers fresh reading from the database on the next read operation In case some other user has made any changes

Complete Example: Menu Selection ”Display All” Reloading all the bookings private void allToolStripMenuItem_Click(object sender, EventArgs e) { LoadData(); } private void LoadData() { Mapper.ClearBookingMapper(); Display(Mapper.BookingMapper.GetAll()); } private void Display(IList<Booking> list) { bookingBindingSource.DataSource = from item in list orderby item.Venue.Name ascending, item.FromTime ascending select item; }