Questions tagged [design-patterns]
A design pattern is a general reusable solution to a commonly occurring problem in software design.
4,450
questions
3
votes
3
answers
399
views
Using Bridge and Strategy together, is my idea correct/useful?
I'm working on a website project for a software engineering course. This site will be using a database to store data, currently through JDBC and MySQL.
Now the first thing I would want to do, is use ...
3
votes
4
answers
2k
views
Design Pattern for Indirectly Connecting Two Classes
Admittedly, this is a homework problem but I have tried to figure it out on my own. Just want to make sure I get it correct. So far, the only design pattern I believe to be correct would be the ...
3
votes
2
answers
5k
views
Implementing strategy pattern multiple variables?
I am trying to implement Strategy Pattern for handling my content serialization and deserialization.
So I have four kind of requests namely CREATE, RETRIEVE, UPDATE, DELETE and for each request I want ...
3
votes
5
answers
16k
views
Constructor overloading or allow null?
Which is the preferred design to use, one constructor that allows null, or two constructors where one throws an ArgumentNullException on null?
Two constructors with exception throwing
public class ...
3
votes
2
answers
2k
views
Using MVC style, where is the best place to put SQL functionality?
I am wondering about best practices here.
MVC (Model - View - Controller) patterns involve separating components of your program that model the data, manipulate those models, and display those ...
3
votes
2
answers
360
views
Is there a name for this pattern?
A while loop can be written as follows in C# (and many other languages):
int someValue;
int someTerminatingValue;
while ((someValue = GetSomeValue()) != someTerminatingValue)
{
// Do something ...
3
votes
5
answers
325
views
OODesign: Data Structure which calls algorithm on insert
I have a data structure which has an add function.
When the user instantiates a new data structure object, she can specify an algorithm which will be executed each time the add function is called and ...
3
votes
3
answers
3k
views
How to implement the repository pattern for an app that will change its database from sql to nosql on in couple of years?
I have been reading a lot about repository implementation. I am confused about which way to implement it for a project I am sure would change its data layer methods because of db migration from MS Sql ...
3
votes
2
answers
330
views
To subclass or to wrap for "default" implementation?
I'm creating a toolset in Java consisting of many Natural Language Processing (NLP) tools, such as Tokenizer, POS tagger, Lemmatizer, Sentence parsing, etc.
I want to put all good and publicly ...
3
votes
3
answers
4k
views
How does Observer create loosely-coupled design?
I completely understand the Observer design pattern, what it is for and how to implement it. I also understand what the term 'loosely-coupled' means.
But I'm not sure how Observer makes designs more ...
3
votes
2
answers
768
views
OOP way to design a manager of groups of users
Alright. I have this pattern to model that comes in two variations that are very much the same. I have a class which can be considered an "entry point" which will call a few manager classes depending ...
3
votes
2
answers
358
views
Is there a name for being able to quickly find the relevant code? [closed]
I notice that a property of codebases that I like hacking on is that it's quick to find the relevant code for some feature, without knowing much about the code base at all. For example, searching for ...
3
votes
2
answers
2k
views
How can I decouple configuration data from the program that uses it?
I am a beginning programmer who has written a spider application in PHP. Currently there are three parts:
1) The Spider (spider.php)
2) The Harvester (harvest.php)
3) The Configuration file (for ...
3
votes
2
answers
1k
views
What patterns book for iOS development contains this specific information? [closed]
I've read several books on iOS development and Objective-C, however what a lot of them teach is how to work with interfaces and all contain the model inside the view controller, i.e. a ...
3
votes
2
answers
277
views
Is it dangerous for me to give some of my Model classes Control-like methods?
In my personal project I have tried to stick to MVC, but I've also been made aware that sticking to MVC too tightly can be a bad thing as it makes writing awkward and forces the flow of the program in ...
3
votes
4
answers
295
views
How to "translate" interdependent object states in code?
I have the following problem. My UI interace contains several buttons, labels, and other visual information. I am able to describe every possible workflow scenario that should be be allowed on that ...
3
votes
3
answers
950
views
New Silverlight app. MVVM. RIA Services vs CSLA
Another 2 days of reading and watching demos and here we go.
For my enterprise LoB Silverlight app I'm going to use:
Prism for UI aspects and modularity.
MVVM pattern (using Prism)
??? to bring data ...
3
votes
1
answer
102
views
Shell Script Design Patteren: Source a library file VS Call different files?
We discuss about POSIX compliant shell script here.
While we are writing more and more shell scripts, we build some helper functions to reuse the codes.
We are considering putting a few helper ...
3
votes
3
answers
901
views
CQRS in a data heavy application involving a lot of CRUD
I've been developing a non-trivial personal application and I thought I'd use CQRS to learn it. The application is very data entry heavy, lots of entities and lots of forms. I find myself constantly ...
3
votes
5
answers
320
views
Add specific behavior inside classes
I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we ...
3
votes
1
answer
6k
views
Repository Pattern with Services Layer - Good Practice?
This is my first time I am using repository pattern and applying a layered architecture in a project. I have followed the article found here. The complete code found on the article can also be found ...
3
votes
2
answers
505
views
Abstract Factory: Can Client Class have an aggregation with the Factory?
After searching for some Abstract Factory examples using modern programming languages, I have some dillemas about the sensu lato of conceptual UML schema of Abstract, more specificly about the Client (...
3
votes
1
answer
241
views
Design Pattern: Extending existing functionaliy of ENUM
Let me explain the problem I am dealing with. I have a custom (jar) API that I use in my production code. This API contains an ENUM that looks as follows:
public enum Cars {
AUDI("BERLIN", "...
3
votes
2
answers
2k
views
How to deal with UI data requirements in DDD
I'm using DDD and a CQRS/Event Sourcing architecture so my domain logic is separated in a microservice (e.g: command service) and the read side is in another microservice (e.g: query service).
We ...
3
votes
1
answer
319
views
How to make updates to data and return list of updates without breaking Command query separation or DRY?
I have a use case to make updates to a slightly complex JSON object and then return the list of changes made (not the updated data). The process of finding the list of changes is extremely similar to ...
3
votes
1
answer
2k
views
C++ design pattern for template instantiation based on run time information?
Say I want to be able to create objects for a range of template parameter
template<int a> class Myclass : public MyclassSuper{...};
And I want to create objects like
Myclass<...
3
votes
3
answers
2k
views
How to handle large switch statement running several different commands?
I've been tasked with refactoring a console application, which is constantly running on a server and receiving messages from a service bus.
Right now, it just parses the incoming message, and based ...
3
votes
2
answers
3k
views
Design pattern for applying different taxes based on many different factors
I've been given the task to design a system that has a product's price have different amounts of different taxes based on different factors.
For example in the US you would get a few - one based on ...
3
votes
1
answer
5k
views
How to design anti-corruption layer in DDD
I'm getting ready to create an integration with a major external system and was wondering if my understanding of the design pattern for this in domain driven design was solid.
Considerations:
...
3
votes
1
answer
1k
views
Connect observers to observable automatically using dependency injection container
I have several services that implement an observer interface and one service that implements the corresponding observable interface.
I'm currently using unity together with Prism so I would prefer to ...
3
votes
2
answers
252
views
Translate data between inconsistently-matched data structures
How can my program best represent a translation between imperfectly-matched data structures?
I am tasked with a one-way translation of data from one system to another. Both systems are established, I ...
3
votes
3
answers
1k
views
Preemptive interfaces in Java - good, bad or "a matter of taste"
I frequently come across projects that strictly define an interface for each and every class. 90% of those interfaces feature only a single implementation. Proponents of these "preemptive interfacs" ...
3
votes
2
answers
231
views
Could this be called a decorator pattern?
I want to add some extra methods closely related to Book without extending Book. So I found the decorator pattern.
Most examples I have seen are eg. extending an abstract decorator class which ...
3
votes
1
answer
1k
views
Strategy Pattern not sufficient for my problem?
Let me sketch the situation:
I have multiple users, with certain properties (2 enums)
For each user I need to fetch data, for some with some basic filtering, for some extended filtering (= basic ...
3
votes
2
answers
163
views
How do you handle sequentiallity in API's?
Consider a use case of the form:
The system shows a list of potential filters (by name, by creation time...).
User chooses a filter and supplies necessary parameters.
System shows a list of potential ...
3
votes
2
answers
1k
views
Is turning a method into a class to use it across many classes bad practice? [closed]
Let's say I have a sort method inside of my class and another class that has no relationship with that class needs the same method. Instead of writing that method twice and breaking the do not repeat ...
3
votes
3
answers
656
views
What is the most efficient way to find a set of locations within a radius of a certain point?
Imagine a dataset of all the restaurants in the US (similar to Yelp, etc), how would you return a set of restaurants within a certain range of a particular zip code. (Assuming you have already a ...
3
votes
4
answers
565
views
Would implementing a "Throwable Event System" be abusive?
I have been thinking for a couple years now about using Throwable events and implementing a sort of event system that uses throw to dispatch an event, or let a different method handle it with throws.
...
3
votes
3
answers
1k
views
Design suggestions for converters in Java
I'm trying a set of converters which will convert an object to some older form. And there are different objects which are converted. By older form I mean changing the values of some fields and in case ...
3
votes
3
answers
4k
views
Design a Queuing Solution with Clustering and Multiple Consumers
It is a Design Problem which I am listing out here.
I have different set of business operations that are carried out for different business entities.
Operations:
Operation A
Operation B
Operation ...
3
votes
2
answers
594
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 ...
3
votes
3
answers
2k
views
OOP what is meant by object-to-object communication
I've been reading in basic concepts of OOP,as i'm trying to make this shift from transactional scripts to more oop manner in php, and i often come across this definition :
An object stores its ...
3
votes
3
answers
197
views
When to use tools vs custom development? [closed]
To learn dependency injection in a current side-project, I am writing my own dependency injection container.
But this has lead me to wonder, at what point is it worthwhile to use a third party ...
3
votes
1
answer
460
views
Creating a online database creator
I've been thinking of creating an online database creator (think DabbleDB, Zoho Creator, Intuit Quickbase, etc.).
I've been thinking of a couple solutions:
Have 4 database tables: Tables, Rows, ...
3
votes
2
answers
426
views
How to abstract transition between Views?
Our team is developing an application using WPF with MVVM.
We want to make ViewModels reusable. With this intention we want to abstract the transition logic between Views (ViewModels, we use ...
3
votes
3
answers
427
views
Which design pattern would be best for this case?
I have a class, called PolicyProvider, at present with the following (abridged) interface:
public interface IPolicyProvider
{
List<Policy> GetRenewalPolicies(Client client, int ...
3
votes
2
answers
979
views
Thinking pragmatically about scalability
I was recently asked as an exercise to design a scalable graph.
My first intuition was how to seperate the graph and distribute it (sharding,consistent hashing..etc)
Turns out my thinking was on ...
3
votes
2
answers
253
views
Should I split out synchronization from my class and what's it called?
When thinking about testability and modular code, I recently thought about whether I should split out the synchronization part of a class from the actual behavior part.
By example:
The app "needs" ...
3
votes
2
answers
196
views
Determining which decorator classes are available via reflection
I'm creating a pizza place application where employees will be able to create orders for customers(pizza and any number of toppings). This is for a school project but the requirements have nothing to ...
3
votes
4
answers
449
views
Would Using a PHP Framework Be Beneficial in My Context?
I've just started work at a small start-up company who mainly uses PHP to develop their front-end apps. I had no prior PHP experience before joining, and this has led to my apps becoming large pieces ...