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

learn more… | top users | synonyms (1)

3
votes
0answers
43 views

What is the correct place to put checking of conditions in this use case?

Here is the situation: I have a database and a class that is basically a representation of a set of fields of different tables in it. Let's call it Message. "Message" does not know of the database ...
0
votes
2answers
56 views

How to better define SRP and “wholesome” objects? [duplicate]

Assume you have a class. It can really be any class that defines a domain concept like an employee, a product on an e-commerce site, or a car. One of those examples that are oldies but goodies. ...
4
votes
1answer
142 views

Understanding factories

I know there are hundreds of questions about this on here. I've probably read fifty different questions, blog posts and textbooks. The problem is I've gotten about 75 different answers. I have seen ...
1
vote
1answer
28 views

Best pattern for manager class that handles syncing objects between client and server

I am writing a client which has support of 'offline mode'. When offline records can be stored locally. When we go online we want to be able to synchronize these records with the remote API. I want ...
3
votes
0answers
26 views

Best practice for defining and keeping related stateless methods together in Objective-C

I have a few methods which are stateless: loginWithEmail: password: completion: signUpWithEmail: password: completion: resetPasswordForUsername: completion: Currently what I do is I create a class ...
2
votes
1answer
39 views

Pattern for “Assembling” result from multiple datasources

I'm creating a server in Java (although this question is language agnostic) that will do the following: Pull a set of "leads" from a database every 10 minutes For all leads with a certain marker, ...
0
votes
0answers
33 views

Is there a good pattern for building nested form objects with validations?

I'm using the form object pattern to handle data normalization and validation in my app. It's working well for simple cases, but some of my form objects are composites (or roll-ups) of multiple other ...
1
vote
2answers
69 views

What is a good way to organize service layer classes?

I had a Service layer in my app and, for a while, there's just one class for API calls Current Scenario MyAPI Class authenticateApp() authenticateUser() Looking in the future, that class will be ...
0
votes
1answer
52 views
+50

Accepted Patterns For Base Class with both Static And User-Defined Data Sources

I have a requirement to build a 'base' profile library (in C# - NET 4.5.2) for various different internal (technical) consumers. This profile consists of metadata fields that would be shared by a ...
0
votes
2answers
138 views

Design Patterns: What design pattern should I use for the following? [duplicate]

I am trying to write an utility which traverses through a list of files and searches for a string in each file. On finding the string in a file, I will add it to a list and display the list. Which ...
3
votes
0answers
51 views

Which is the preferable design for my Gateway?

I'm writing a Gateway class that extracts information from a HTML document. One of the responsibilities of the class is to traverse a table in the document and extract data from its rows. I'm trying ...
1
vote
1answer
96 views

Could there be a use case for C# style auto-properties in Python

I've been doing a lot of work in C# recently (my primary language is Python) and I love that I can do something like public string MyProperty{ get; set; } Going back to Python I miss that sort of ...
1
vote
3answers
57 views

How to reuse domain model logic in services?

I am trying to avoid anemic domain models as it's said to be an anti-pattern. But doing so leaves my services to duplicate some of the logic. class User { public $status; public function ...
2
votes
1answer
69 views

Define an object with the interface as a type instead of class name [duplicate]

I try to practice with the design patterns and explore one of the possible implementations of the Observer Design Pattern in Java. I paid attention, that in this example the object is defined with the ...
1
vote
1answer
37 views

Where to put the domain in MVCS

From what I've read and understand MVCS (Model-View-Controller-Store) is a design pattern that lets you do the following: View - Application view, what the user will see. Controllers - Manages the ...
6
votes
1answer
74 views

Optional features: default method or separated interface

Dedicated interfaces seems to be a good way to expose the optional features in a domain-specific type hierarchy. However, they impede the use of decorator and composite patterns, which is also common ...
1
vote
1answer
74 views

How/should I introduce a new pattern into my codebase [closed]

I have recently discovered the Builder pattern and the Step Builder pattern which are essentially just like object initialisers but with the Step Builder pattern you can add mandatory fields. We have ...
1
vote
3answers
149 views

Handling if-statements with a known duration [duplicate]

I wasn't sure exactly what to call these situations, so I'll illustrate it. If I have something like this in a method: if (i <= 5) doSomething(); else doSomethingElse(); but I know ...
4
votes
2answers
98 views

C++ design for encoder/decoder classes with different stored types

I need to handle different elements in a vector, each element owning a specific parameter (integer or string), so that I can easily handle encoding/decoding of a series of elements. Encoding a list ...
-1
votes
2answers
94 views

MVC is a kind of Design Pattern? [duplicate]

While I was trying to concrete the concept of design pattern, I came up with a question: As I asked in the title, Is MVC(Model-View-Controller) architecture kind of Design Pattern?
0
votes
1answer
47 views

How to better isolate JOGL or LWJGL3 dependency from game clients?

I'm currently working on a project to develop a relatively small framework with the goal of supporting game development efforts for students in a course. The scope of this project is an OpenGL-based ...
1
vote
3answers
143 views

Design pattern for different code behaviors according to different clients

At my company, we have a solution composed of a WinForm (multiple per client) and an API (one per client). This solution is deployed on different clients that require the solution to behave ...
2
votes
3answers
670 views

Unknown design pattern

I am currently trying to refactor some code and one of the problems I came across was the constructors had far too many parameters (15 in fact) and was being initialised by another object which had ...
0
votes
1answer
51 views

Should the server and client portions of an SPA be separate repos? [closed]

I'm building an SPA (my first), and I had a question about organization. (I'm using Node.js for the server and Browserify & React for the client, and that's mildly important later). I'm unsure if ...
2
votes
0answers
99 views

is this a valid javascript design pattern when many instances are required?

I have some code that I'm refactoring, right now its just a list of functions, primarily jQuery. The code is a form builder. The user adds sections, questions etc using jqueryUI drag/drop/sort. They ...
2
votes
2answers
121 views

Handling insertion to database with Repository pattern

I have a design question for working with databases in object-oriented PHP. I have a table in my database called products. Then I have 2 classes for this table in my PHP project. ...
2
votes
4answers
200 views

Using variable + method invocation or repeating invocation?

Here is two methods that does the same thing. One is repeating the call to the method Print where the other one does not but has an additional variable. class Program { static void Main(string[] ...
1
vote
1answer
106 views

What is the name of the pattern for passing an incomplete object to a constructor? [closed]

Several times in javascript I've seen a constructor function take in one parameter. The constructor will initialize all the fields for the object to default values and then use the parameter to ...
8
votes
6answers
3k views

How to reduce a switch in a switch statement?

So I'm making a method to create a salutation line based on two people from a database. There are four parameters: the two names (name1 and name2) and the two genders (gender and gender2). For every ...
1
vote
1answer
57 views

What's the difference between a Factory method and Entity Translator

The entity translator provides a function that takes one or more data contract classes as parameters and returns a specific business entity. Within the implementation of the function, a new ...
0
votes
2answers
176 views

Is there a name for this data structure pattern consisting of a list of dictionaries each with one entry, consisting of an object? [closed]

There is a data structure idiom that looks something like this: [ { obj_1_id: { key1: value1_1, key2: value2_1 } }, { obj_2_id: { key1: ...
0
votes
1answer
57 views

Issues deciding on approach to create object

I'm trying to decide what's the best approach to instantiate a particular class. Basically there are two use cases for it: instantiate it in order to save a new entry to the database and fetch an ...
1
vote
2answers
246 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 ...
0
votes
0answers
28 views

What's the difference between Transaction Script and Service Objects?

Recently I saw so many people talk about Transaction Script and Service Objects. For example, the Transaction Script in this article: The glory of Transaction Script is its simplicity. Organizing ...
0
votes
2answers
113 views

The correct way of declaring & instantiating variables ( Javascript ) [duplicate]

I have seen other peoples code and each person has a different way of declaring variables. And I have been told by quite a few people that declaring variables in the Global Scope is wrong. My ...
1
vote
2answers
297 views

How to use SOLID principles in this example

I have reading about SOLID principles last week and decided to try to solve real world problem by using them. So I got the problem of real world ecommerce site managing totals. Problem Statement: ...
1
vote
1answer
80 views

Pattern for communicating between nested usercontrols and parent form (C# / Winforms)

I'm trying to decide the best way to handle communication between a UserControl that is nested within another UserControl and the parent Form itself. I have a Form, inside the form there's a ...
3
votes
1answer
57 views

How should I handle incompatible configurations with the Bulider pattern?

This is motivated by this answer to a separate question. The builder pattern is used to simplify complex initialization, especially with optional initialization parameters). But I don't know how to ...
4
votes
1answer
228 views

When to use Prototypes & the correct usage of Prototypes ( Javascript )

I have been programming in Javascript for a while and I am quite comfortable with it. And I know the basic concept of prototypes and I have also used them a few times. But one thing I can't figure out ...
3
votes
2answers
87 views

Building a class that contains built classes

I have some classes I've created that are immutable and follow the builder pattern. I'm now creating a composite class that will include those classes as fields. Should the builder for that composite ...
2
votes
1answer
82 views

How to implement role permissions in service layer?

In my current project i have Report class and i am going to implement service layer for it. Every method will be allowed only for some roles. Like this. public class ReportService : IReportService { ...
0
votes
0answers
47 views

Haskell + OpenGL framework

I'm writing a framework in Haskell where I'd like to use OpenGL to draw lines, shapes... I'm encountering a problem defining the structure of my program. I have for example a Polyline type which holds ...
0
votes
1answer
99 views

How to access a variable that I only need to create once on Application.Start

According to this guide: https://github.com/mspnp/azure-guidance/blob/master/Retry-Service-Specific.md They say: Note that the StackExchange.Redis client uses multiplexing through a single ...
3
votes
5answers
263 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 ...
1
vote
3answers
142 views

What is a good Design Pattern for a bundle of methods that comprises an algorithm?

This is a Design question relating to finding out a good OO design pattern or design structure or class combination that can house an algorithm that processes user selection to produce product ...
0
votes
0answers
24 views

Accessing data in widget

Background I started to get involved in a project written in python and wxPython (for the GUI). My task is to debug and add a few features to the GUI. The widgets are organised mainly with sizers, ...
2
votes
1answer
256 views

What design patterns could be used here?

I'm trying to come up with a nice design (preferably pythonic) for the following use case. Say there's three services - A, B, C in multiple locations L1, L2, L3, etc. Each service provides ...
5
votes
1answer
138 views

How to prevent multiple form submissions when user reloads the page

I'm currently working on a project which requires that we integration a 3rd party SOAP API to handle a number of basic CRUD type operations. Our current implementation allows us to leveraging the ...
-3
votes
2answers
137 views

Advantages of these recommendations in ooprogramming using Java

Below are the recommendation from section 5.1 of this essay. While Java is not a pure object-oriented language, it is possible to program in a pure object-oriented style by obeying the following ...
1
vote
1answer
69 views

DTOs vs Domain Models and invoking Command Handlers directly

I was just hoping someone might be able to answer a few questions I have regarding the proper design of DTOs and Domain Models. I'm currently working on a project which involves leveraging a SOAP API. ...