A design pattern is a general reusable solution to a commonly occurring problem in software design.

learn more… | top users | synonyms (1)

1
vote
2answers
192 views

global try-catch in presentation layer

I have a 3-layered app structured as follows. Presentation Layer (ASP.NET MVC project) Business Logic Layer (Services for controllers in PL) Data Access Layer (Repositories) Each Controller in PL ...
2
votes
2answers
477 views

A small project but I want to use design patterns to do it right

I've got a project coming up, a very a small system, but one that needs to be extended in the future. Here's how I've designed it so far. It's 3-tier: presentation, business and data. For the ...
0
votes
2answers
267 views

Why don't we completely de-couple frontend JS frameworks and backend APIs? [closed]

Whenever we implement a frontend framework in the likes of Backbone, AngularJS etc. there's an integration process involved with the backend technologies like NodeJS, Rails, Yii etc. (like setting up ...
1
vote
2answers
295 views

Correct way to inject dependencies in Business logic service?

Currently the structure of my application is as below Web App --> WCF Service (just a facade) --> Business Logic Services --> Repository -> Entity Framework Datacontext Now each of my Business logic ...
1
vote
7answers
358 views

Using a Simple/Static Factory vs. instantiating directly: new Thing() vs. factory.createThing() - what's the benefit?

Here are two ways to instantiate an object: Option 1: Thing thing = new Thing(); Option 2: (the factory is a Static Factory, but it could also be a Simple Factory). Thing thing = ...
0
votes
1answer
62 views

Algorithmic Forecasting and Pattern Recognition

Say a user could enter project data into my software. Each project has 2 variables "size" and "work" and they're related but the relationship is not known. Is there a way to programmatically determine ...
-1
votes
1answer
146 views

Correct pattern for Worker Processes involving Queues & Tables

Edit: OK, so, people said it is unclear what I am asking. I am asking for feedback on this design. Here is an example user story: As a group admin on the website I want to be notified when a user in ...
0
votes
1answer
48 views

Restricting object types that can be added to each other using the Composite Pattern

The Situation: I am building a custom PHP application framework. I have implemented a composite pattern so I can build a object tree representing the page to be rendered. Example: abstract class ...
-4
votes
1answer
115 views

How is the Decorator Pattern actually used in practice? [closed]

I understand completely how to implement the Decorator pattern, and I also understand what it's intent is. The Decorator is used in one of two cases: As an alternative to subclassing - when there ...
0
votes
2answers
137 views

Is using interfaces on internal code a good idea? [duplicate]

I'm working on a set of automated tests that we use internally at work. Lately, we've been designing classes that implement interfaces in addition to inheritance. As I understand it, interfaces in ...
0
votes
1answer
195 views

pattern to share objects between API and application

I'm having serious doubts about the design for my Web application. I wanted to separate the business logic from the interface so I made a Web API that handles all the requests to the database. It's ...
2
votes
1answer
141 views

Adapter Pattern: Design Patterns

So far as I know, there are two forms of the Adapter Pattern: the class adapter and the object adapter. Could someone please explain to me the following limitation of the class adapter and why it is ...
0
votes
0answers
31 views

Organizing an image processing pipeline for on-the-fly video analysis

I'm trying to design a system that performs image analysis on video streams from the internet. I have a few rudimentary ideas for how to organize such a system, and I was hoping you guys could ...
3
votes
1answer
79 views

Access items of a container with a pattern

I've two C++ classes with a relation: a container class which has a list of items. For example a library has got many books. The classes are the library and the book. Now from the external world I ...
2
votes
1answer
93 views

What's the right OO way to create a counter/inventory class that works for both differentiated and undifferentiated countables?

You are writing a videogame about trading beans. Red beans, black beans, pinto beans, you name it. As everybody knows all beans are the same. You write the "Inventory" class for a trader in that ...
0
votes
0answers
59 views

Build a map with city blocks and road

Is there a design pattern or well known algorithm to build a simple map with roads and city blocks? To have an idea of what's my target i describe some of the constraints and the context: a matrix ...
2
votes
1answer
68 views

Use adapter pattern for coupled classes

I need (for unit testing purposes) to create adapters for external library classes.ExchangeService and ContactsFolder are Microsoft's implementations in its' EWS library. So I created my adapters that ...
2
votes
2answers
210 views

What do I gain by using the Strategy pattern in this case?

I wrote a program with Java that plays simple music. Currently chords have only one way ('strumming pattern') to be played. I want to expand this and create different 'strumming patterns' that chords ...
0
votes
1answer
82 views

MVC: Where should I store interchangeable algorithms used by the Model (whose names also need to be accessible to the View)?

Please consider a program, where the user chooses an algorithm from a list, and the Strategy pattern is utilized to set this algorithm as the model's operation. For example, an image procession ...
6
votes
2answers
216 views

Javascript MVC application design (canvas)

I'm having difficulty grasping how to structure/architect a canvas application using an MVC like approach in Javascript. UI will be fairly fluid and animated, the games fairly simplistic but with ...
5
votes
4answers
212 views

How to take things step by step

This is about the third time I've had to write software to control a cellular modem. For those unfamiliar with the process, you have a sequence of steps you have to take. Each step takes a certain ...
1
vote
4answers
134 views

Dealing with similar objects with different method signatures

I am fairly new to OO design and have problems with the design of some software and looking for a pattern or a combination of patterns that could help me solving my problem. I have a type that has a ...
1
vote
0answers
77 views

Methods for structuring JavaScript SDKs

I've built a REST API and have been using Backbone models throughout a couple different applications to communicate to it. I would really like to build a single JS SDK that can be used in any ...
0
votes
0answers
55 views

RESTful composition/inclusion of other resources

I have a few HTTP resources, and i'm wondering if including the models of one in the other is acceptable or if there is a cleaner method. In this example, we have a ton of "news" resources, and users ...
0
votes
1answer
173 views

Domain Services vs. Factories vs. Aggregate Roots

After dealing with DDD for months now, I'm still confused about the general purposes of domain services, factories and aggregate roots in relation to each other, e.g. where they overlap in their ...
0
votes
2answers
48 views

Handling ignorable failure conditions in a method

I'm working on a coarse API for performing higher level business functions. Under many conditions these functions may fail in a way that is expected (not exceptional), ie. the function may not be ...
-1
votes
4answers
183 views

Where should you put functions and variables that are only needed by one function in a class?

Say you have a Car class. Properties that make sense for a Car class might be: var make; var model; var year; var turnOn; // a function But the turnOn function is very complicated and ends up ...
1
vote
2answers
90 views

Logging events for reporting purposes

Are there any design patterns or best practices around logging events for use in reporting and BI systems. For example in a system which manages orders from a website, it would be beneficial if a ...
14
votes
4answers
673 views

Progressive Enhancement vs. Single Page Apps

I just got back from a conference in Boston called An Event Apart. A really popular theme amongst the speakers was the idea of progressive enhancement - a site's content should go in the HTML, and ...
0
votes
2answers
182 views

What is the Loopback Pattern? [closed]

I was reading this blog post about Hexagonal architecture and at the bottom it says: The Loopback pattern is an explicit pattern for creating an internal replacement for an external device. When ...
5
votes
1answer
416 views

To Repository Or Not To Repository

When I first learnt about Domain Driven Design, I was also introduced to the repository and unit of work patterns that once seemed to be top notch for the cool kids that threw SQL queries like ...
2
votes
1answer
121 views

Where do utility libraries fit in a layered architecture?

Consider this mock-up of a software stack designed with layered architecture in mind : Every application layer is decoupled through API calls, but a memory handling library is used throughout. All ...
1
vote
0answers
26 views

PaypalCheckout object is composed of PaypalQuery objects. Hide PaypalQuery objects to users of PaypalCheckout?

I have a PaypalCheckout object that handles the checkout process: from initiating API calls, to providing an interface for front-end code (e.g. View/Controller). The PaypalCheckout object handles: ...
0
votes
1answer
102 views

Traversing an AST using Visitors

I'm writing a compiler for a C-like language, and I'm looking for an elegant way to traverse my abstract syntax tree. I'm trying to implement the Visitor pattern, although I'm not convinced that I'm ...
0
votes
2answers
160 views

Optimization ended up in casting an object at each method call

I've been doing some optimization for the following piece of code : public void DrawLine(int x1, int y1, int x2, int y2, int color) { _bitmap.DrawLineBresenham(x1, y1, x2, y2, color); } After ...
0
votes
1answer
131 views

Is the following example a strategy pattern?

In my problem I had lots of objects with slightly different behaviour, but identical attributes and methodes with identical interfaces. The objects variants were quite big in number, and I didn't want ...
0
votes
2answers
51 views

Easiest way to use objects as filters for queries

I'm just starting on a new little pet project of mine. I started the project using a familiar pattern for using objects as "filters" in SQL Queries. I've never been much happy about its easy of use, ...
0
votes
0answers
44 views

Modelling network and persistent entity representations

I have an app where I need to synchronize some entities (simply download latest versions of entities from server to client). Entity has bunch of text properties and bunch of resource links (referenced ...
1
vote
1answer
77 views

How to deal with interactions between many objects

I've been working on a game in my spare time. I'm pretty much done defining the primitives and until today everything was pretty well segmented and encapsulated but now it's come time to implement ...
1
vote
2answers
104 views

Visitor only applicable when using the Composite pattern?

For a long time I've tried to get my head wrapped around the visitor pattern, and somehow this thing keeps being rather fuzzy to me. I'm currently under the impression it is only useful to apply ...
1
vote
3answers
147 views

Relative encapsulation design

Let's say I am doing a 2D application with the following design: There is the Level object that manages the world, and there are world objects which are entities inside the Level object. A world ...
5
votes
4answers
372 views

Adding field to the class at runtime - design pattern

Imagine your customer want's to have a possibility to add new property (e.g. color) to product in their eshop in their CMS. Instead of having properties as fields: class Car extends Product { ...
3
votes
1answer
103 views

Best approach for tracking dependent state

Let's pretend I work on a project tracking application. The application is a database backed, server hosted, web application. In this application there are Projects which have many Activities which ...
1
vote
2answers
443 views

When is it worth NOT using a Factory?

I'm employing TDD quite a bit these days and really enjoying myself - everything seems to flow better and be naturally better constructed and organized. However, while writing a bit of IO code, ...
0
votes
2answers
213 views

Can this argument be enough?

We have two C++ classes named Important and Small The class Small use a few methods and attributes from the class Important, but not all. Since our application is performance critical, instead of ...
18
votes
5answers
3k views

How would another popular language avoid having to use the factory pattern while managing similar complexity as in Java/Java EE?

Factory pattern (or at least the use of FactoryFactory..) is the butt of many jokes, like here. Apart from having verbose and "creative" names like ...
1
vote
1answer
164 views

How to make my code decide which class to instantiate based on a parameter?

I have a system in which I will perform queries to a database. I want Query1, Query2 and Query3 to use the same methods in their way to the data source layer. To do that I would like to make ...
0
votes
2answers
214 views

Design Pattern: Algorithm varies according to the input arguments

I will give a simple example to help you understand my question. Suppose we have a rectangle and a Utility class with a method that creates a buffer arround a shape. The .createBuffer method has ...
1
vote
1answer
164 views

Should I use inheritance or an interface?

So in a nutshell I have an abstract class : public abstract class Member { public string PCode { get; set; } public string Reference { get; set; } public DateTime? ElectedDate { get; set; } } And ...
0
votes
1answer
180 views

Implementing a strategy pattern with dependency injection

Okay, so the goal here is to implement a strategy pattern that can be tested using any sort of automated testing tool. I've been struggling with this problem conceptually for a few weeks now and I ...