SlideShare ist ein Scribd-Unternehmen logo
1 von 65
Downloaden Sie, um offline zu lesen
HÖNNUN OG SMÍÐI HUGBÚNAÐAR 2015
L15 ORGANISING DOMAIN LAYER
Agenda
Layering
The Three Principal Layers
Domain layer Patterns
Transaction Script
Domain Model
Table Module
Service Layer
From Problem to Pattern
Building the domain
Reading
Domain Model
Multilayered Architecture
P of EAA:
Table Module
Domain Model
Transaction Script
Service Layer
Layering
Layering
▪ Software systems can get complicated
– Abstractions are needed
▪ Layering provides abstraction by separating computer
systems in layers
– Higher layers use services from

lower layers
– Each layer has dedicated tasks

and hides complexity from upper

layers
Benefits of Layering
▪ You can understand a single layer as a coherent whole
without knowing much about other layers
▪ You can substitute layers with alternative implementation of
the same basic service
▪ You minimise dependencies between layers
▪ Layers make good places for standardisation
▪ Once you have a layer built, you can use it for many higher-
level services
Downsides
▪ Layers encapsulate some, but not all, things well
– Cascading changes
– For example adding a field in the UI requires changes on each layer
▪ Extra layers can harm performance
– At every layer things typically need to be transformed from one
presentation to another
▪ Organisational problems
– If difference teams work on different layers, code duplications and other
problems emerge
– Conway’s Law
The Three Principal Layers
The Three Layers
▪ Presentation
– User’s interface to the system
– User can be another system
– Accepts input, displays views
▪ Domain
– The Application of the system
– The “Business logic”
– Tends to creep into presentation and
– data source
▪ Data Source
– Connection to the database
– Also Persistence
Where is the Business Logic?
▪ “Business Logic”
– or “Complex business illogic”?
– Business Rules including all special cases
– It is easy to think of business logic but difficult to spot – many corner
cases
– Also referred to as Domain Logic
▪ Enterprise software has a lot of “noise”
– “Plumbing” code around the domain logic
– Is getCustomer domain logic?
– Application Logic – or workflow
How to define Domain Logic?
▪ Definition
– If all environment (noise) is taken way, what is left should be
domain logic
– Environment is any middleware (web, data, ejb)
▪ Domain Logic should be
– Simple classes and interfaces – POJOs
– Easy to test!
– Easy to move around
– Easy to access
▪ Limited dependencies
– Dependencies can be reduced by injection
The Three Layers
▪ Dependencies
– Presentation gets information from lower layers, preferable Domain
Layer
– Domain or Data Source Layers should not depend on the
Presentation Layer
– Domain Layer depends on Data Source Layer
– Data Source Layer could use some objects from the Domain Layer
Presentation
Layer
Domain
Layer
Data Source
Layer
Logic that is not Domain Logic
▪ Logic in different places
Application Logic
Presentation
Layer
Presentation
Logic
Domain
Layer
Domain
Logic
Data Source
Layer
Data Source
Logic
Presentation Layer
Web
Browser
Native
Apps
Web
Layer
Domain Layer Data Source
Layer
HTTP
request Request
Controller
Presentation
View
HTTP
response
Service Layer
Domain Model
Table 

Data
Gateway
CMS containing HTML with JavaScript, native apps
REST API to input controllers
Presentation Layer
Presentation Logic
▪ How to display items, how things look
– Which colours to choose
– Number and Date formats, zero padding
▪ The presentation should
– Have easy and unified access to the data
– Avoid having assumptions on the data
– Avoid the need to calculate based on the data
▪ Example view models
– HTML
– Server pages JSP, ASP
– Native Apps, Windows, iOS, Android
Data Source Logic
▪ How to query and store items
– Optimisation
– Data manipulation for upper layer
▪ The Data Source Layer should
– Provide simple interface to the domain layer
– Maintain speed and integrity
– Hide the database layout from the object model
▪ Example data model
– DAO
– Stored procedures, triggers
Application Logic
▪ Having to do with application responsibilities
– “Workflow” logic
– Noise
▪ Example:
– Notifying contract administrator
– Checking HTTP parameters and selecting which controller to pass
the responsibility to the model
Interfaces
▪ Users can be other programs or services
– Presentation is an external interface that you provide as a service to
others
▪ Data can be other systems
– Data source is an external interface of services that you use
Domain
Layer
Domain
Logic
Services
used
Services
offered
Where is the Business Logic?
▪ Create a specific Layer for the Domain Logic
– Well know patterns like Domain Model
– An object model of the domain that incorporates both behaviour
and data
– Object-oriented programming!!!
Web
Browser
Web
Layer
Domain Layer Data Source
Layer
Native
App
Where is the Business Logic?
▪ Flooding of logic...
▪ If you don’t provide a place for the Domain Logic it will find a place –
usually a wrong one!
Web
Browser
Web
Layer
Data Source
Layer
Native
App
Enterprise Web Layers
▪ Clients usually run on the user’s machine
– Separate tier
– Web Browser or Rich Internet Application (RIA)
– Can also be processes or other applications
▪ Web Components run on a Web Server
▪ Domain Components run on Application Server
– Web Server or EJB Server for EJBs
▪ Data Source Components run on the same Application Server (as
the domain)
▪ Database is usually on a separate tier
Domain Layer Design Patterns
Domain Layer
▪ Provides the business logic of the application
– Not part of the Presentation Layer nor the Data Source layer
Web
Browser
Native
Apps
Web
Layer
Domain Layer Data Source
Layer
HTTP
request Request
Controller
Presentation
View
HTTP
response
Service Layer
Domain Model
Table 

Data
Gateway
Presentation Layer
Domain Layer Patterns
▪ Transaction Script
– Organizes business logic by procedures where each procedure
handles single request from the presentation
▪ Domain Model
– An object model of the domain that incorporates both data and
behaviour
▪ Table Module
– One class that provides domain logic to table or view in database
Transaction Scripts
Organises business logic by procedures 

where each procedure handles a single request from the
presentation
▪ Most business applications can be thought of as a series of
transactions
– A Transaction Script organises all this logic primarily as a single
procedure
Image from: PoEAA
Transaction Scripts
▪ Works well if model is simple
– Small amount of logic
– No state needed
– Moving data between presentation and database
▪ Problems
– Code duplication between transactions
– Common code tends to be duplicated
– Since no state is used, and each transaction is separate from any
other, there might be too many calls to database layer
Transaction Scripts
▪ Revenue recognitions example
– One script handles all the logic
– Uses a data gateway to access data
Image from: PoEAA
Domain Model
An object model of the domain that

incorporates both behavior and data
▪ Rules and logic describe many different cases and slants of
behaviour
▪ Web of interconnected objects
– Where each object represents some meaningful entity
– Dependencies between objects
▪ How it works
– Object that represent data and business rules (behaviour)
Domain Model
▪ Simple model
– Similar to the database design
– Simple to map to the database
▪ Rich model
– Different from the database

design
– Better for solving some

complex logic and doing

calculation
Image from: PoEAA
Domain Model
▪ Revenue recognitions example
– Multiple classes each with different responsibility
– Each class has data and logic to calculate
Image from: PoEAA
Table Module
A single instance that handles the business logic for all rows in a
database table or view
▪ Organises domain logic with one class per table in the database
– Single instance of the class contains various procedures that will
act on the data
– One object per table handle
▪ How it works
– One class that provides domain logic to table or view in database
– A Domain Model will have one order object per order while a Table
Module will have one object to handle all orders
Table Module
▪ When to use it
– Useful when application is centered on data
– Objects in the model are similar to the database
Image from: PoEAA
Comparing
Table ModuleDomain Model
Transaction Script
Image from: PoEAA
Making a Choice
▪ Pattern depends on
– Complexity of the domain logic and
– How the domain maps to the database
Service Layer
Defines an application’s boundary with a layer of services
that establishes a set of available operations and
coordinates the application’s response in each operation
▪ Defines an application's boundary
– Provides a set of available operations from the perspective of
interfacing client layers
– Encapsulates the application's business logic
Service Layer
▪ Domain façade
– Provides thin interface

to the Domain Model
– Does not implement

any business logic
▪ Operation Script
– Implementation of

application logic
– Use the Domain Model

for domain logic
–
Image from: PoEAA
Design with Service Layer
Web
Browser
Native
Apps
Web
Layer
Domain Layer Data Source
Layer
HTTP
request Request
Controller
Presentation
View
HTTP
response
Table 

Data
Gateway
Presentation Layer
POJOs
Domain logic
Service Layer
▪ Service Layer provides API bounder to the Domain Model
I	
  want	
  to	
  structure	
  my	
  domain	
  layer	
  and	
  use	
  a	
  pattern	
  that	
  applies	
  to	
  each	
  
situation:	
  
A) The	
  logic	
  is	
  rather	
  extensive	
  
B) The	
  logic	
  is	
  simple	
  and	
  procedure	
  based	
  
C) The	
  logic	
  is	
  moderate	
  and	
  is	
  centered	
  around	
  the	
  database
EXERCISE
From Problem to Pattern
How	
  do	
  I	
  structure	
  my	
  domain	
  layer?	
  
A)	
  The	
  logic	
  is	
  rather	
  extensive	
  
Domain	
  Model
Domain Model
An object model of the domain that

incorporates both behavior and data
▪ Rules and logic describe many different cases and slants of
behaviour
▪ Web of interconnected objects
– Where each object represents some meaningful entity
– Dependencies between objects
▪ How it works
– Object that represent data and business rules (behaviour)
From Problem to Pattern
How	
  do	
  I	
  structure	
  my	
  domain	
  layer?	
  
B)	
  The	
  logic	
  is	
  simple	
  and	
  procedure	
  based	
  
Transac@on	
  Script
Transaction Scripts
Organises business logic by procedures 

where each procedure handles a single request from the
presentation
▪ Most business applications can be thought of as a series of
transactions
– A Transaction Script organises all this logic primarily as a single
procedure
Image from: PoEAA
From Problem to Pattern
How	
  do	
  I	
  structure	
  my	
  domain	
  layer?	
  
C)	
  The	
  logic	
  is	
  moderate	
  and	
  is	
  centred	
  around	
  the	
  database	
  
Table	
  Module
Table Module
A single instance that handles the business logic for all rows in a
database table or view
▪ Organises domain logic with one class per table in the database
– Single instance of the class contains various procedures that will
act on the data
– One object per table handle
▪ How it works
– One class that provides domain logic to table or view in database
– A Domain Model will have one order object per order while a Table
Module will have one object to handle all orders
From Problem to Pattern
How	
  do	
  I	
  give	
  my	
  domain	
  logic	
  

dis@nct	
  API?	
  
Service	
  Layer
Service Layer
Defines an application’s boundary with a layer of services
that establishes a set of available operations and
coordinates the application’s response in each operation
▪ Defines an application's boundary
– Provides a set of available operations from the perspective of
interfacing client layers
– Encapsulates the application's business logic
From Problem to Pattern
Problem – Ru Movie DB (rumdb)
From Problem to Pattern
▪ We need to build a solution
– We know the problem – sort of
▪ To get to the solution
– What patterns to use?
Rumdb	
  
The	
  RU	
  Movie	
  Database
SolutionProblem
Application Layer
Solution?
▪ How to we get to this?
Domain LayerWeb
Browser
Native
Apps
HTTP
request
HTTP
response
POJOs
Domain logic
Service Layer
Web
Layer
Request
Controller
Presentation
View
Data Source
Layer
Table 

Data
Gateway
How to define Domain Logic?
▪ Definition
– If all environment (noise) is taken way, what is left should be
domain logic
– Environment is any middleware (web, data, ejb)
▪ Domain Logic should be
– Simple classes and interfaces – POJOs
– Easy to test!
– Easy to move around
– Easy to access
▪ Limited dependencies
– Dependencies can be reduced by injection
Building the Domain
▪ Objects – the nouns
– Movie, Ratings, Channel, …
▪ User Stories
– What you do with the objects
▪ Example
– As a Operator, I want to add new movie
– As a User, I want to get all movies for a specific channel
– As a User, I want to rate specific movie
Movie Database Example
Movie Database Example
▪ The Service Layer
– MovieService Provides simple and clean interface for manipulation
of Movies
– External services can be injected into the Service Layer
Movie Database Example
▪ MovieService
– Provides an interface to manipulate Movies
public class MovieService extends ApplicationService
{
private MovieDataGateway movieDataGateway;
public void addMovie(Movie movie) throws ServiceException
{
movie.initialize();
if(!movie.validate())
{
throw new ServiceException("Movie is invalid");
}
movieDataGateway.addMovie(movie);
getMailGateway().SendMessage("netfang@ru.is", "netfang@ru.is", 

"New Movie", "New Movie was added!");
}
...
}
Movie Database Example
▪ ApplicationService
– Layer Supertype for the Service Layer
– Provides support for all service classes
public class ApplicationService
{
private MailGateway mailGateway;
public MailGateway getMailGateway()
{
return mailGateway;
}
public void setMailGateway(MailGateway mailGateway)
{
this.mailGateway = mailGateway;
}
}
Movie Database Example
▪ The Domain Model
– POJOs with attributes and operations
Movie Database Example
▪ Movie
– Object for describing and manipulating contents
– Has a Rating object which keeps count of views and rates
public class Movie implements Comparable
{
private int id;
private String title;
private String link;
private String description;
private Date release;
private String director;
private Rating rating = new Rating();
private List<Validator> validators = new ArrayList<Validator>();
Movie Database Example
▪ Methods in Movie
public void initialize()
{
rating.reset();
clearValidators();
addValidator(new DefaultMovieValidator(this));
}
public boolean validate()
{
for(Validator v : validators)
{
if(!v.validate())
return false;
}
return true;
}
Movie Database Example
▪ Methods in Movie
– Has validators – easily extendable according to the Open-Close
Principle
public void clearValidators()
{
validators.clear();
}
public void addValidator(Validator validator)
{
validators.add(validator);
}
Movie Database Example
▪ Methods in Movie
public void view()
{
rating.incrementView();
}
public void rate(int rate)
{
rating.incrementRate(rate);
}
public double getAverageRate()
{
return rating.getAverageRate();
}
Movie Database Example
▪ Rating
public class Rating
{
private int views; // Number of requests
private int rates; // Number of rates
private int score; // Combined values of scores
public void incrementView()
{
views++;
}
public void incrementRate(int rate)
{
rates++;
score += rate;
}
public double getAverageRate()
{
return score/rates;
}
Movie Database Example
Movie Database Example
▪ TestSimple
public TestSimple()
{
MovieService movieService = new MovieService();
movieService.setMovieDataGateway(new MovieDataGatewayStub());
movieService.setMailGateway(new MailServerStub());
try {
movieService.addMovie(new Movie(1, "Movie 1”, "http1", "", new Date(), ""));
movieService.addMovie(new Movie(1, "Movie 2", "http2", "", new Date(), ""));
movieService.addMovie(new Movie(1, "Movie 3", "http3", "", new Date(), ""));
movieService.addMovie(new Movie(1, "Movie 4", "http4", "", new Date(), ""));
}
catch (ServiceException sex) { ... }
List<Movie> list = movieService.getMovies();
for (Movie movie : list)
{
System.out.println(movie);
}
Summary
▪ Layering
▪ Three Principal Layers
▪ Domain layer Patterns to choose from
– Transaction Script for simple business logic
– Domain Model for complex business logic
– Table Module for moderate business logic when you have good
tools around Record Set
– Service Layer to provide API
▪ Building the domain
▪ From Problem to Pattern

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex code
EdwinOstos
 
Concepts of Asp.Net
Concepts of Asp.NetConcepts of Asp.Net
Concepts of Asp.Net
vidyamittal
 
Adf & Jdeveloper overview
Adf & Jdeveloper overviewAdf & Jdeveloper overview
Adf & Jdeveloper overview
Rohan Walia
 

Was ist angesagt? (20)

Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
 
Introduction to Oracle ADF Task Flows
Introduction to Oracle ADF Task FlowsIntroduction to Oracle ADF Task Flows
Introduction to Oracle ADF Task Flows
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
 
A micro bit of services is all that we need
A micro bit of services is all that we needA micro bit of services is all that we need
A micro bit of services is all that we need
 
Asp.net basic
Asp.net basicAsp.net basic
Asp.net basic
 
ASP.NET - Introduction to Web Forms and MVC
ASP.NET - Introduction to Web Forms and MVCASP.NET - Introduction to Web Forms and MVC
ASP.NET - Introduction to Web Forms and MVC
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex code
 
Jake_Park_resume
Jake_Park_resumeJake_Park_resume
Jake_Park_resume
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
 
An Oracle ADF Introduction
An Oracle ADF IntroductionAn Oracle ADF Introduction
An Oracle ADF Introduction
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6
 
Angular JS and Magento
Angular JS and MagentoAngular JS and Magento
Angular JS and Magento
 
Flamingo Commerce Ports and Adapters
Flamingo Commerce Ports and AdaptersFlamingo Commerce Ports and Adapters
Flamingo Commerce Ports and Adapters
 
XPages: The Next Step In Your Life As A Notes Developer
XPages: The Next Step In Your Life As A Notes DeveloperXPages: The Next Step In Your Life As A Notes Developer
XPages: The Next Step In Your Life As A Notes Developer
 
Concepts of Asp.Net
Concepts of Asp.NetConcepts of Asp.Net
Concepts of Asp.Net
 
Asp.net
 Asp.net Asp.net
Asp.net
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 
SAP Portal Role-Based Navigation Models for Different Countries and Languages.
SAP Portal Role-Based Navigation Models for Different Countries and Languages.SAP Portal Role-Based Navigation Models for Different Countries and Languages.
SAP Portal Role-Based Navigation Models for Different Countries and Languages.
 
Adf & Jdeveloper overview
Adf & Jdeveloper overviewAdf & Jdeveloper overview
Adf & Jdeveloper overview
 

Andere mochten auch (9)

IWMW 1998: Web front-ends to databases
IWMW 1998: Web front-ends to databasesIWMW 1998: Web front-ends to databases
IWMW 1998: Web front-ends to databases
 
ICT support for community groups and small business
ICT support for community groups and small businessICT support for community groups and small business
ICT support for community groups and small business
 
MCITP – Enterprise Administrator
MCITP – Enterprise AdministratorMCITP – Enterprise Administrator
MCITP – Enterprise Administrator
 
Linkedin presentation
Linkedin presentationLinkedin presentation
Linkedin presentation
 
Mark Dzwonczyk at the Common Ground Alliance 2012
Mark Dzwonczyk at the Common Ground Alliance 2012Mark Dzwonczyk at the Common Ground Alliance 2012
Mark Dzwonczyk at the Common Ground Alliance 2012
 
Teori teori etika bisnis
Teori teori etika bisnis Teori teori etika bisnis
Teori teori etika bisnis
 
Presentation gambol
Presentation gambolPresentation gambol
Presentation gambol
 
трикутники в нашому житті
трикутники в нашому життітрикутники в нашому житті
трикутники в нашому житті
 
Учреждения практики
Учреждения практикиУчреждения практики
Учреждения практики
 

Ähnlich wie L15 Organising Domain Layer

Assessing technology landscape
Assessing technology landscapeAssessing technology landscape
Assessing technology landscape
Dom Mike
 
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk ChoStateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Redis Labs
 
How to Build TOGAF Architectures With System Architect (2).ppt
How to Build TOGAF Architectures With System Architect (2).pptHow to Build TOGAF Architectures With System Architect (2).ppt
How to Build TOGAF Architectures With System Architect (2).ppt
StevenShing
 

Ähnlich wie L15 Organising Domain Layer (20)

L13 Oranizing Domain Logic
L13 Oranizing Domain LogicL13 Oranizing Domain Logic
L13 Oranizing Domain Logic
 
L07 Oranizing Domain Logic
L07 Oranizing Domain LogicL07 Oranizing Domain Logic
L07 Oranizing Domain Logic
 
L19 Application Architecture
L19 Application ArchitectureL19 Application Architecture
L19 Application Architecture
 
L11 Application Architecture
L11 Application ArchitectureL11 Application Architecture
L11 Application Architecture
 
L19 Application Architecture
L19 Application ArchitectureL19 Application Architecture
L19 Application Architecture
 
L17 Data Source Layer
L17 Data Source LayerL17 Data Source Layer
L17 Data Source Layer
 
L20 Scalability
L20 ScalabilityL20 Scalability
L20 Scalability
 
L15 Data Source Layer
L15 Data Source LayerL15 Data Source Layer
L15 Data Source Layer
 
Sap basis training demo basis online training in usa,uk and india
Sap basis training demo  basis online training in usa,uk and indiaSap basis training demo  basis online training in usa,uk and india
Sap basis training demo basis online training in usa,uk and india
 
Sap basis training demo basis online training in usa,uk and india
Sap basis training demo  basis online training in usa,uk and indiaSap basis training demo  basis online training in usa,uk and india
Sap basis training demo basis online training in usa,uk and india
 
Introduction and Basics to web technology .pptx
Introduction and Basics to web technology .pptxIntroduction and Basics to web technology .pptx
Introduction and Basics to web technology .pptx
 
Assessing technology landscape
Assessing technology landscapeAssessing technology landscape
Assessing technology landscape
 
LeedsSharp May 2023 - Azure Integration Services
LeedsSharp May 2023 - Azure Integration ServicesLeedsSharp May 2023 - Azure Integration Services
LeedsSharp May 2023 - Azure Integration Services
 
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk ChoStateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
 
Lecture 9: Dynamic web application
Lecture 9: Dynamic web applicationLecture 9: Dynamic web application
Lecture 9: Dynamic web application
 
SAP BASIS Simplified Learning with End to End
SAP BASIS Simplified Learning with End to EndSAP BASIS Simplified Learning with End to End
SAP BASIS Simplified Learning with End to End
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
 
Domain Logic Patterns
Domain Logic PatternsDomain Logic Patterns
Domain Logic Patterns
 
How to Build TOGAF Architectures With System Architect (2).ppt
How to Build TOGAF Architectures With System Architect (2).pptHow to Build TOGAF Architectures With System Architect (2).ppt
How to Build TOGAF Architectures With System Architect (2).ppt
 
L12 Session State and Distributation Strategies
L12 Session State and Distributation StrategiesL12 Session State and Distributation Strategies
L12 Session State and Distributation Strategies
 

Mehr von Ólafur Andri Ragnarsson

L14 From the Internet to Blockchain
L14 From the Internet to BlockchainL14 From the Internet to Blockchain
L14 From the Internet to Blockchain
Ólafur Andri Ragnarsson
 
L12 digital transformation
L12 digital transformationL12 digital transformation
L12 digital transformation
Ólafur Andri Ragnarsson
 
L09 Technological Revolutions
L09 Technological RevolutionsL09 Technological Revolutions
L09 Technological Revolutions
Ólafur Andri Ragnarsson
 

Mehr von Ólafur Andri Ragnarsson (20)

Nýsköpun - Leiðin til framfara
Nýsköpun - Leiðin til framfaraNýsköpun - Leiðin til framfara
Nýsköpun - Leiðin til framfara
 
Nýjast tækni og framtíðin
Nýjast tækni og framtíðinNýjast tækni og framtíðin
Nýjast tækni og framtíðin
 
New Technology Summer 2020 Course Introduction
New Technology Summer 2020 Course IntroductionNew Technology Summer 2020 Course Introduction
New Technology Summer 2020 Course Introduction
 
L01 Introduction
L01 IntroductionL01 Introduction
L01 Introduction
 
L23 Robotics and Drones
L23 Robotics and Drones L23 Robotics and Drones
L23 Robotics and Drones
 
L22 Augmented and Virtual Reality
L22 Augmented and Virtual RealityL22 Augmented and Virtual Reality
L22 Augmented and Virtual Reality
 
L20 Personalised World
L20 Personalised WorldL20 Personalised World
L20 Personalised World
 
L19 Network Platforms
L19 Network PlatformsL19 Network Platforms
L19 Network Platforms
 
L18 Big Data and Analytics
L18 Big Data and AnalyticsL18 Big Data and Analytics
L18 Big Data and Analytics
 
L17 Algorithms and AI
L17 Algorithms and AIL17 Algorithms and AI
L17 Algorithms and AI
 
L16 Internet of Things
L16 Internet of ThingsL16 Internet of Things
L16 Internet of Things
 
L14 From the Internet to Blockchain
L14 From the Internet to BlockchainL14 From the Internet to Blockchain
L14 From the Internet to Blockchain
 
L14 The Mobile Revolution
L14 The Mobile RevolutionL14 The Mobile Revolution
L14 The Mobile Revolution
 
New Technology 2019 L13 Rise of the Machine
New Technology 2019 L13 Rise of the Machine New Technology 2019 L13 Rise of the Machine
New Technology 2019 L13 Rise of the Machine
 
L12 digital transformation
L12 digital transformationL12 digital transformation
L12 digital transformation
 
L10 The Innovator's Dilemma
L10 The Innovator's DilemmaL10 The Innovator's Dilemma
L10 The Innovator's Dilemma
 
L09 Disruptive Technology
L09 Disruptive TechnologyL09 Disruptive Technology
L09 Disruptive Technology
 
L09 Technological Revolutions
L09 Technological RevolutionsL09 Technological Revolutions
L09 Technological Revolutions
 
L07 Becoming Invisible
L07 Becoming InvisibleL07 Becoming Invisible
L07 Becoming Invisible
 
L06 Diffusion of Innovation
L06 Diffusion of InnovationL06 Diffusion of Innovation
L06 Diffusion of Innovation
 

Kürzlich hochgeladen

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

L15 Organising Domain Layer

  • 1. HÖNNUN OG SMÍÐI HUGBÚNAÐAR 2015 L15 ORGANISING DOMAIN LAYER
  • 2. Agenda Layering The Three Principal Layers Domain layer Patterns Transaction Script Domain Model Table Module Service Layer From Problem to Pattern Building the domain
  • 3. Reading Domain Model Multilayered Architecture P of EAA: Table Module Domain Model Transaction Script Service Layer
  • 5. Layering ▪ Software systems can get complicated – Abstractions are needed ▪ Layering provides abstraction by separating computer systems in layers – Higher layers use services from
 lower layers – Each layer has dedicated tasks
 and hides complexity from upper
 layers
  • 6. Benefits of Layering ▪ You can understand a single layer as a coherent whole without knowing much about other layers ▪ You can substitute layers with alternative implementation of the same basic service ▪ You minimise dependencies between layers ▪ Layers make good places for standardisation ▪ Once you have a layer built, you can use it for many higher- level services
  • 7. Downsides ▪ Layers encapsulate some, but not all, things well – Cascading changes – For example adding a field in the UI requires changes on each layer ▪ Extra layers can harm performance – At every layer things typically need to be transformed from one presentation to another ▪ Organisational problems – If difference teams work on different layers, code duplications and other problems emerge – Conway’s Law
  • 9. The Three Layers ▪ Presentation – User’s interface to the system – User can be another system – Accepts input, displays views ▪ Domain – The Application of the system – The “Business logic” – Tends to creep into presentation and – data source ▪ Data Source – Connection to the database – Also Persistence
  • 10. Where is the Business Logic? ▪ “Business Logic” – or “Complex business illogic”? – Business Rules including all special cases – It is easy to think of business logic but difficult to spot – many corner cases – Also referred to as Domain Logic ▪ Enterprise software has a lot of “noise” – “Plumbing” code around the domain logic – Is getCustomer domain logic? – Application Logic – or workflow
  • 11. How to define Domain Logic? ▪ Definition – If all environment (noise) is taken way, what is left should be domain logic – Environment is any middleware (web, data, ejb) ▪ Domain Logic should be – Simple classes and interfaces – POJOs – Easy to test! – Easy to move around – Easy to access ▪ Limited dependencies – Dependencies can be reduced by injection
  • 12. The Three Layers ▪ Dependencies – Presentation gets information from lower layers, preferable Domain Layer – Domain or Data Source Layers should not depend on the Presentation Layer – Domain Layer depends on Data Source Layer – Data Source Layer could use some objects from the Domain Layer Presentation Layer Domain Layer Data Source Layer
  • 13. Logic that is not Domain Logic ▪ Logic in different places Application Logic Presentation Layer Presentation Logic Domain Layer Domain Logic Data Source Layer Data Source Logic
  • 14. Presentation Layer Web Browser Native Apps Web Layer Domain Layer Data Source Layer HTTP request Request Controller Presentation View HTTP response Service Layer Domain Model Table 
 Data Gateway CMS containing HTML with JavaScript, native apps REST API to input controllers Presentation Layer
  • 15. Presentation Logic ▪ How to display items, how things look – Which colours to choose – Number and Date formats, zero padding ▪ The presentation should – Have easy and unified access to the data – Avoid having assumptions on the data – Avoid the need to calculate based on the data ▪ Example view models – HTML – Server pages JSP, ASP – Native Apps, Windows, iOS, Android
  • 16. Data Source Logic ▪ How to query and store items – Optimisation – Data manipulation for upper layer ▪ The Data Source Layer should – Provide simple interface to the domain layer – Maintain speed and integrity – Hide the database layout from the object model ▪ Example data model – DAO – Stored procedures, triggers
  • 17. Application Logic ▪ Having to do with application responsibilities – “Workflow” logic – Noise ▪ Example: – Notifying contract administrator – Checking HTTP parameters and selecting which controller to pass the responsibility to the model
  • 18. Interfaces ▪ Users can be other programs or services – Presentation is an external interface that you provide as a service to others ▪ Data can be other systems – Data source is an external interface of services that you use Domain Layer Domain Logic Services used Services offered
  • 19. Where is the Business Logic? ▪ Create a specific Layer for the Domain Logic – Well know patterns like Domain Model – An object model of the domain that incorporates both behaviour and data – Object-oriented programming!!! Web Browser Web Layer Domain Layer Data Source Layer Native App
  • 20. Where is the Business Logic? ▪ Flooding of logic... ▪ If you don’t provide a place for the Domain Logic it will find a place – usually a wrong one! Web Browser Web Layer Data Source Layer Native App
  • 21. Enterprise Web Layers ▪ Clients usually run on the user’s machine – Separate tier – Web Browser or Rich Internet Application (RIA) – Can also be processes or other applications ▪ Web Components run on a Web Server ▪ Domain Components run on Application Server – Web Server or EJB Server for EJBs ▪ Data Source Components run on the same Application Server (as the domain) ▪ Database is usually on a separate tier
  • 23. Domain Layer ▪ Provides the business logic of the application – Not part of the Presentation Layer nor the Data Source layer Web Browser Native Apps Web Layer Domain Layer Data Source Layer HTTP request Request Controller Presentation View HTTP response Service Layer Domain Model Table 
 Data Gateway Presentation Layer
  • 24. Domain Layer Patterns ▪ Transaction Script – Organizes business logic by procedures where each procedure handles single request from the presentation ▪ Domain Model – An object model of the domain that incorporates both data and behaviour ▪ Table Module – One class that provides domain logic to table or view in database
  • 25. Transaction Scripts Organises business logic by procedures 
 where each procedure handles a single request from the presentation ▪ Most business applications can be thought of as a series of transactions – A Transaction Script organises all this logic primarily as a single procedure Image from: PoEAA
  • 26. Transaction Scripts ▪ Works well if model is simple – Small amount of logic – No state needed – Moving data between presentation and database ▪ Problems – Code duplication between transactions – Common code tends to be duplicated – Since no state is used, and each transaction is separate from any other, there might be too many calls to database layer
  • 27. Transaction Scripts ▪ Revenue recognitions example – One script handles all the logic – Uses a data gateway to access data Image from: PoEAA
  • 28. Domain Model An object model of the domain that
 incorporates both behavior and data ▪ Rules and logic describe many different cases and slants of behaviour ▪ Web of interconnected objects – Where each object represents some meaningful entity – Dependencies between objects ▪ How it works – Object that represent data and business rules (behaviour)
  • 29. Domain Model ▪ Simple model – Similar to the database design – Simple to map to the database ▪ Rich model – Different from the database
 design – Better for solving some
 complex logic and doing
 calculation Image from: PoEAA
  • 30. Domain Model ▪ Revenue recognitions example – Multiple classes each with different responsibility – Each class has data and logic to calculate Image from: PoEAA
  • 31. Table Module A single instance that handles the business logic for all rows in a database table or view ▪ Organises domain logic with one class per table in the database – Single instance of the class contains various procedures that will act on the data – One object per table handle ▪ How it works – One class that provides domain logic to table or view in database – A Domain Model will have one order object per order while a Table Module will have one object to handle all orders
  • 32. Table Module ▪ When to use it – Useful when application is centered on data – Objects in the model are similar to the database Image from: PoEAA
  • 34. Making a Choice ▪ Pattern depends on – Complexity of the domain logic and – How the domain maps to the database
  • 35. Service Layer Defines an application’s boundary with a layer of services that establishes a set of available operations and coordinates the application’s response in each operation ▪ Defines an application's boundary – Provides a set of available operations from the perspective of interfacing client layers – Encapsulates the application's business logic
  • 36. Service Layer ▪ Domain façade – Provides thin interface
 to the Domain Model – Does not implement
 any business logic ▪ Operation Script – Implementation of
 application logic – Use the Domain Model
 for domain logic – Image from: PoEAA
  • 37. Design with Service Layer Web Browser Native Apps Web Layer Domain Layer Data Source Layer HTTP request Request Controller Presentation View HTTP response Table 
 Data Gateway Presentation Layer POJOs Domain logic Service Layer ▪ Service Layer provides API bounder to the Domain Model
  • 38. I  want  to  structure  my  domain  layer  and  use  a  pattern  that  applies  to  each   situation:   A) The  logic  is  rather  extensive   B) The  logic  is  simple  and  procedure  based   C) The  logic  is  moderate  and  is  centered  around  the  database EXERCISE
  • 39. From Problem to Pattern How  do  I  structure  my  domain  layer?   A)  The  logic  is  rather  extensive   Domain  Model
  • 40. Domain Model An object model of the domain that
 incorporates both behavior and data ▪ Rules and logic describe many different cases and slants of behaviour ▪ Web of interconnected objects – Where each object represents some meaningful entity – Dependencies between objects ▪ How it works – Object that represent data and business rules (behaviour)
  • 41. From Problem to Pattern How  do  I  structure  my  domain  layer?   B)  The  logic  is  simple  and  procedure  based   Transac@on  Script
  • 42. Transaction Scripts Organises business logic by procedures 
 where each procedure handles a single request from the presentation ▪ Most business applications can be thought of as a series of transactions – A Transaction Script organises all this logic primarily as a single procedure Image from: PoEAA
  • 43. From Problem to Pattern How  do  I  structure  my  domain  layer?   C)  The  logic  is  moderate  and  is  centred  around  the  database   Table  Module
  • 44. Table Module A single instance that handles the business logic for all rows in a database table or view ▪ Organises domain logic with one class per table in the database – Single instance of the class contains various procedures that will act on the data – One object per table handle ▪ How it works – One class that provides domain logic to table or view in database – A Domain Model will have one order object per order while a Table Module will have one object to handle all orders
  • 45. From Problem to Pattern How  do  I  give  my  domain  logic  
 dis@nct  API?   Service  Layer
  • 46. Service Layer Defines an application’s boundary with a layer of services that establishes a set of available operations and coordinates the application’s response in each operation ▪ Defines an application's boundary – Provides a set of available operations from the perspective of interfacing client layers – Encapsulates the application's business logic
  • 47. From Problem to Pattern
  • 48. Problem – Ru Movie DB (rumdb)
  • 49. From Problem to Pattern ▪ We need to build a solution – We know the problem – sort of ▪ To get to the solution – What patterns to use? Rumdb   The  RU  Movie  Database SolutionProblem
  • 50. Application Layer Solution? ▪ How to we get to this? Domain LayerWeb Browser Native Apps HTTP request HTTP response POJOs Domain logic Service Layer Web Layer Request Controller Presentation View Data Source Layer Table 
 Data Gateway
  • 51. How to define Domain Logic? ▪ Definition – If all environment (noise) is taken way, what is left should be domain logic – Environment is any middleware (web, data, ejb) ▪ Domain Logic should be – Simple classes and interfaces – POJOs – Easy to test! – Easy to move around – Easy to access ▪ Limited dependencies – Dependencies can be reduced by injection
  • 52. Building the Domain ▪ Objects – the nouns – Movie, Ratings, Channel, … ▪ User Stories – What you do with the objects ▪ Example – As a Operator, I want to add new movie – As a User, I want to get all movies for a specific channel – As a User, I want to rate specific movie
  • 54. Movie Database Example ▪ The Service Layer – MovieService Provides simple and clean interface for manipulation of Movies – External services can be injected into the Service Layer
  • 55. Movie Database Example ▪ MovieService – Provides an interface to manipulate Movies public class MovieService extends ApplicationService { private MovieDataGateway movieDataGateway; public void addMovie(Movie movie) throws ServiceException { movie.initialize(); if(!movie.validate()) { throw new ServiceException("Movie is invalid"); } movieDataGateway.addMovie(movie); getMailGateway().SendMessage("netfang@ru.is", "netfang@ru.is", 
 "New Movie", "New Movie was added!"); } ... }
  • 56. Movie Database Example ▪ ApplicationService – Layer Supertype for the Service Layer – Provides support for all service classes public class ApplicationService { private MailGateway mailGateway; public MailGateway getMailGateway() { return mailGateway; } public void setMailGateway(MailGateway mailGateway) { this.mailGateway = mailGateway; } }
  • 57. Movie Database Example ▪ The Domain Model – POJOs with attributes and operations
  • 58. Movie Database Example ▪ Movie – Object for describing and manipulating contents – Has a Rating object which keeps count of views and rates public class Movie implements Comparable { private int id; private String title; private String link; private String description; private Date release; private String director; private Rating rating = new Rating(); private List<Validator> validators = new ArrayList<Validator>();
  • 59. Movie Database Example ▪ Methods in Movie public void initialize() { rating.reset(); clearValidators(); addValidator(new DefaultMovieValidator(this)); } public boolean validate() { for(Validator v : validators) { if(!v.validate()) return false; } return true; }
  • 60. Movie Database Example ▪ Methods in Movie – Has validators – easily extendable according to the Open-Close Principle public void clearValidators() { validators.clear(); } public void addValidator(Validator validator) { validators.add(validator); }
  • 61. Movie Database Example ▪ Methods in Movie public void view() { rating.incrementView(); } public void rate(int rate) { rating.incrementRate(rate); } public double getAverageRate() { return rating.getAverageRate(); }
  • 62. Movie Database Example ▪ Rating public class Rating { private int views; // Number of requests private int rates; // Number of rates private int score; // Combined values of scores public void incrementView() { views++; } public void incrementRate(int rate) { rates++; score += rate; } public double getAverageRate() { return score/rates; }
  • 64. Movie Database Example ▪ TestSimple public TestSimple() { MovieService movieService = new MovieService(); movieService.setMovieDataGateway(new MovieDataGatewayStub()); movieService.setMailGateway(new MailServerStub()); try { movieService.addMovie(new Movie(1, "Movie 1”, "http1", "", new Date(), "")); movieService.addMovie(new Movie(1, "Movie 2", "http2", "", new Date(), "")); movieService.addMovie(new Movie(1, "Movie 3", "http3", "", new Date(), "")); movieService.addMovie(new Movie(1, "Movie 4", "http4", "", new Date(), "")); } catch (ServiceException sex) { ... } List<Movie> list = movieService.getMovies(); for (Movie movie : list) { System.out.println(movie); }
  • 65. Summary ▪ Layering ▪ Three Principal Layers ▪ Domain layer Patterns to choose from – Transaction Script for simple business logic – Domain Model for complex business logic – Table Module for moderate business logic when you have good tools around Record Set – Service Layer to provide API ▪ Building the domain ▪ From Problem to Pattern