background preloader

Other Types of Design Patterns

Facebook Twitter

The Specification Pattern - Jeff Perrin - Sexier Than You Are. Hot on the heels of my devastatingly fantastic post on an implementation of the Snapshot Pattern, I give you my next piece du resistance. In this little post, I'd like to delve into the Specification Pattern. So what the heck is it? Matt Berther provided a pretty good introduction where he states: It's primary use is to select a subset of objects based on some criteria... That pretty much sums it up. What we want to do is extract out a specification for a subset of objects we might be interested in.

You'll see something like this in a lot of applications: public List GetHighPricedSaleProducts(){ List list = new ArrayList(); for(Product p in Products){ if(p.IsOnSale && p.Price > 100.0){ list.Add(p); } } return list; } public List GetHighPricedSaleProducts(){ List list = new ArrayList(); for(Product p in Products){ if(p.IsOnSale && p.Price > 100.0){ list.Add(p); } } return list; } Now the first loop I wrote can be written like so: This is a slight improvement...

Mediator pattern. Software architecture design pattern Overview[edit] The mediator[1] design pattern is one of the twenty-three well-known design patterns that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse. Problems that the mediator design pattern can solve[2][edit] Tight coupling between a set of interacting objects should be avoided.It should be possible to change the interaction between a set of objects independently.

Defining a set of interacting objects by accessing and updating each other directly is inflexible because it tightly couples the objects to each other and makes it impossible to change the interaction independently from (without having to change) the objects. Tightly coupled objects are hard to implement, change, test, and reuse because they refer to and know about many different objects. Solutions described by the mediator design pattern[edit] Definition[edit] UnitOfWork Pattern (with Repository) Method 1: The Beginner's Out-of-the-Box Entity Framework Design The Entity Framework is quite powerful. With a few clicks in Visual Studio, we can instantly create an ORM relational model of our database, ready for querying. One of the most simplest implementation of accessing data with the Entity Framework in a C# ASP .NET web application would be the following: void Main() { // Instantiate the Entity Framework data context in a using statement. using (MyEntities context = new MyEntities()) { // Create a dragon.

Dragon dragon = new Dragon(); dragon.Name = "Fang"; dragon.Age = 210; // Create a weapon. In the above code, we've implemented the basic Entity Framework data context within a using block. The basic C# ASP .NET Entity Framework sample demonstrates using the ORM objects and persisting to the database. The Repository Pattern is a Repository .. is a Repository Multiple Entity Framework Context Blocks void Page_Load() { // Create a weapon. Void Page_Load() { // Create a weapon. Java and J2EE Design Pattern - Service Locator.

Service Locator Design Pattern (Page 1 of 2) :: BlackWasp Software Development.

Service Layer Design Pattern

Repository Design Pattern.