יום ראשון, 30 בינואר 2011

Design Patterns


Domain Logic Patterns

Transaction Script
Transaction Script is the organization of business logic in a linear, procedural fashion. It maps finegrained
business use cases to fine-grained methods.
Active Record
Active Record organizes business logic in a way that closely matches the underlying data structure,
namely an object that represents a row in a table.
Domain Model
The Domain Model pattern is an abstraction of real domain objects. Both data and behavior are
modeled. Complex relationships between objects can exist that match the real domain.
You will look at how to use each of these patterns in ASP.NET and when it is appropriate to choose
one pattern over another.

Object Relational Mapping
Unit of Work
The Unit of Work pattern is designed to maintain a list of business objects that have been changed
by a business transaction, whether that be adding, removing, or updating. The Unit of Work then
coordinates the persistence of the changes as one atomic action. If there are problems, the entire
transaction rolls back.
Repository
The Repository pattern, by and large, is used with logical collections of objects, or aggregates as they
are better known. It acts as an in-memory collection or repository for business entities, completely
abstracting away the underlying data infrastructure.
Data Mapper
The Data Mapper pattern is used to hydrate an object from raw data and transfer information from
a business object to a database. Neither the business object nor the database is aware of the other.
Identity Map
An Identity Map keeps tabs on every object loaded from a database, ensuring everything is loaded
only once. When objects are subsequently requested, the Identity Map is checked before retrieving
from the database.
Lazy Loading
Lazy or deferred loading is the act of deferring the process of obtaining a resource until it’s needed.
If you imagine a Customer object with an address book, you could hydrate the customer from the
database but hold the population of the address book until the address book is needed. This enables
the on-demand loading of the address book, thus avoiding the hit to the database if the address data is never needed.
Query Object
The Query Object pattern is an implementation of a Gang of Four interpreter design pattern. The query
object acts as an object-oriented query that is abstracted from the underlying database, referring to
properties and classes rather than real tables and columns. Typically, you will also have a translator
object to generate the native SQL to query the database.

Web Presentation Patterns
Model-View-Presenter, Model-View-Controller,Front Controller, Page Controller

Base, Behavioral, and Structural Patterns
Null Object Pattern
Also known as the Special Case pattern, this acts as a return value rather than returning null to
the calling code. The null object will share the same interface or inherit from the same base class
as the expected result, which alleviates the need to check for null cases throughout the code base.
Separated Interface
The Separated Interface pattern is the act of keeping the interfaces in a separate assembly or namespace
to the implementations. This ensures that the client is completely unaware of the concrete implementations
and can promote programming to abstractions rather than implementations and the Dependency
Inversion principle.
Gateway
The Gateway pattern allows clients to access complex resources via a simplified interface. The Gateway
object basically wraps the resource API into a single method call that can be used anywhere in the application. It also hides any API complexities
All of the enterprise patterns introduced here will be covered in more detail throughout the book
with exercises to see how they are implemented in an ASP.NET scenario.

אין תגובות:

הוסף רשומת תגובה