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

learn more… | top users | synonyms

1
vote
0answers
37 views

Object-oriented implementation of a real-world scenario of using a bathroom - follow-up

This is revised code for the previous question: Object-oriented implementation of a real-world scenario of using a bathroom Is there any object oriented way or design pattern I can use to make this ...
4
votes
0answers
31 views

Controller for a vehicle servicing AJAX app

I am working on a codebase that operates in the following manner: ...
6
votes
1answer
46 views

Portfolio object made of Asset classes and Securities

I am learning Swift and object oriented programming. I am new to design patterns and protocol oriented programming. In my test code I have several related objects: ...
6
votes
1answer
86 views

Object-oriented implementation of a real-world scenario of using a bathroom

Is there any object oriented way or design pattern I can use to make this code better? How can I avoid casting in this code? What if I add new Object like WaterTank ...
2
votes
1answer
51 views

Abstract factory pattern for implementing AdNetworks on multiple platforms [on hold]

Here's the link to the github project. I want to implement abstract factory instead of adding platform-dependent compilation flags in just one file and make it ugly, hence decoupled code. Moreover, ...
1
vote
0answers
24 views

Pattern-matching-esque code

I've come across a need for code like this a few times - you have an object (or objects) that may or may not have certain properties and values within those properties. Consider a program with ...
1
vote
0answers
29 views

TreeNode with nested super as parent

I found a way to use the JLS as a tree-structure (at least in let the parent-field disappear). Please ignore the main-method. It works, but from OOD would you say this is ok? ...
1
vote
1answer
60 views

Unity3D script for controlling a character

This is a Unity3D script I wrote for my game to control a character. I don't consider myself a highly-skilled coder, so I come here to ask for suggestions. Is my code clean enough? How can I improve ...
2
votes
0answers
50 views

Dynamic graph in C++11 with shortest path algorithm

I've been designing a dynamic graph to improve my understanding of C++11. The dynamic aspect means that it could represent the hyperlink structure of a chunk of the internet, with node deletion ...
1
vote
0answers
43 views

Find the appropriate transformer for an abstract value

I want to get rid of the following code duplication within the MyFacadeBean. Consider the following situation: ...
0
votes
1answer
34 views

Implementation of bridge design pattern for a web scraping app - follow-up

Earlier today I tried to implement an example of the bridge design pattern, but I ended up misinterpreting it. I made a lot of changes: ...
0
votes
1answer
44 views

Implementation of Bridge Design Pattern

I made an implementation of the Bridge Pattern to handle ever-changing in crawler APIs that I'm using in my APP. ...
3
votes
1answer
47 views

Class structure to handle API exchange

I'm developing a simple application that crawls web pages to obtain some information. For this I used and tested some libraries, like crawler4j, jsoup, jaunt and htmlunit. I change the crawler APIs ...
3
votes
1answer
56 views

Wrapping decorator pattern with a builder

I'm working on a booking application and am in the process of porting some legacy code to a more SOLID and testable architecture. Right now I'm working on the process of canceling bookings. Over the ...
3
votes
0answers
23 views

Grouping functionality in JavaScript using an Object

I am creating a drawing-app. I want to have a toolbar populated with tools. Each tool is defined in a separate js file. Right now i have defined each tool as an object that contains functions and ...
5
votes
1answer
83 views

Option<T> functional type implementation and scenarios

Have you ever being implementing Option<T> functional type? It is discussed here. Basically, it is about using ...
2
votes
1answer
31 views

Need a better way to create subclass instances from a base class reference

FeatureMap contains features, derived classes have some mandatory features that the map should have, say keys (the mandatory part) are added and all the features are fetched from somewhere. Since ...
3
votes
2answers
85 views

3-level deep if-else tree for constructing a neural network

The following code fragment constructs different types of neural networks outputs based on the options supplied. Currently, my code just has a huge note that describes what all the options are ...
1
vote
1answer
57 views

Converting long list of if/else [closed]

In order to convert a code such as: ...
2
votes
1answer
40 views

Dynamic Dispatch replacement for Generic methods

Type erasure is giving me nuts recently. I'm designing a class that performs symbolic differentiation on a math expression represented as a binary expression tree. The question is more on the design ...
4
votes
1answer
155 views

Implement mail sending system elegantly

In my project I need to send emails. Emails will have different credentials and senders. I'm thinking about "abstract factory", but will it be good solution? ...
0
votes
0answers
85 views

Repository pattern best practices

Which option is better? In the first case, I use a universal repository that can work with any entities. The methods of this repository have many parameters, such as string queries, table names, ...
2
votes
0answers
94 views

ASP.NET MVC with automatic testing (follow up)

This is a follow-up of this question regarding MVC application architecture fit for automatic testing. I have rewritten the DI code based on the answer provided there and also created some tests to ...
4
votes
1answer
103 views

Bloch's Builder Pattern / Updater

I'm creating many builders where I use inheritance. My resources have many properties and are stored in a Repository. In rare case I need to update them. When I update, I need to keep the same ...
1
vote
2answers
94 views

Array class to replace all iterator needs

Following dreams, I have started learning Java for Game Programing purposes and, during code I figured out that Iterators such as Queue, Lists, Arraylists and what not are very common. I have written ...
6
votes
1answer
54 views

1 or 2 Player CLI Tic-Tac-Toe

I wrote a simple tic-tac-toe program in Haskell. It runs on the command line, has a one and two player mode, and implements a minimax algorithm when you play against it. I'm used to writing proper ...
3
votes
1answer
37 views

C++ Template for one to many Registration (pre Gang of Four)

I use this template to lookup clients registered for data. The data is associated by name(key) and clients are shared pointers (value) to a class which will consume the data. ...
8
votes
1answer
52 views

Encapsulating Complex Calculation in JavaScript

This is code for performing a calculation that should be repeated with different levels and temperatures. I am concerned about the organization of this code as I feel it may contain too many helper ...
1
vote
1answer
84 views

ASP.NET MVC application architecture fit for Unit Testing with Mocking

I am trying to learn how to professionally work with Unit Testing, so I have refactored a medium sized project of mine (a sort of article aggregator that also does some ...
5
votes
1answer
71 views

How Godly does an object need to be before it becomes unholy?

I've been told that using God objects at all is a Bad Thing™ In object oriented languages, God objects know all, they control too much. I'm trying to build a game (or for the scope of this question a ...
0
votes
3answers
25 views

Filling name accounts

I think the content is too large and I am deeply think about how to refactor it. Does anyone have good advice on refactoring it? ...
7
votes
1answer
97 views

Refactoring of a client API to avoid duplicated code and unclear passage of parameters

I need to develop an API. The functions of the API are requests that call the services exposed by a server. Initially the API worked like this: ...
6
votes
4answers
240 views

Simple factory retrieving object by name

Despite the fact that this code works, I would like to know if there's any situation I did not anticipated, and/or if what I am trying to do is some what wrong. -std=C++11 flag needed ...
5
votes
1answer
76 views

Model of an mp3 player with state and prototype design patterns

After reading about design patterns in general, I decided to try and incorporate them in an actual program. I chose a State machine for my first exercise, or, more concretely, an MP3 player. The ...
12
votes
1answer
94 views

To read a book thou should have it bought, to buy a book thou should have it found! (Search Abstraction)

I started a hobby project to find the books that I read (paperbacks) so that I can keep track of them (reading start date, finish date, number of pages, etc..) The first challenge was to find the ...
3
votes
1answer
101 views

Is my design is still a state design pattern, or some abomination?

I was trying to review state design pattern, and tried to create flexible implementation of it so it could reuse it in future. So I came out with this: ...
5
votes
2answers
97 views

Query Builder pattern with use of FluentApi

Recently, I've come up with an idea of building a custom query builder combine with FluentApi. Expected usage: ...
3
votes
3answers
159 views

Unit of Work Pattern for creating users

CreateUser function assumes the data being delivered via parameters are clean and gets called or initiated from the Business Manager (another class). This function is responsible to do the following ...
-1
votes
2answers
63 views

Is there a better way of modeling the routines in my operations that doesn't involve PROTECTED fields?

In my application, well-defined operations on collections of business entities are modularized and carried out using one or more routines, each of which operates on a unique type of data associated ...
7
votes
1answer
125 views

Using commands as deferred behaviour

I was thinking of building a really flexible fluent API for my persistence layer. One of my goals is to achieve somehow the following result: ...
10
votes
2answers
135 views

Executing a stored procedure with optional attributes

Lately, I have been reading Uncle Bob's Clean Code book, and decided to try and follow some of his principles to make a class that was a somewhat confusing static helper class, with an abundance of ...
4
votes
3answers
166 views

Using factory pattern to create email templates

Firstly I try to explain my model. I have 3 type of notifications which can have N types of email templates related to a specific status. ...
1
vote
0answers
42 views

Arbitrary function redirection at runtime

This code is for my upcoming challenge on PPCG. The key part of this challenge is supposed ability to overwrite functions that other people have written. Overwriting functions will happen at ...
4
votes
1answer
108 views

Abstract Factory Pattern

Hi everyone I've just done an exercise on the abstract factory pattern. And I want someone corrects the exercise by telling me if I follow the rules of the abstract factory pattern or not. Here is ...
1
vote
1answer
39 views

List of variables, split based on pattern

In my application i keep repeating writing this pattern. I just cant figure out how to write it better. Coming to you for suggestions: ...
2
votes
1answer
100 views

Strategy pattern implementation feedback

I would like to have some feedback on my code, basically because I have been spending a few hours visiting other options before I ended up with this one, so I'm not sure I'm clear enough to value it. ...
3
votes
1answer
53 views

Mapping different classes to the same database table

I have several very similar subclasses that I (think I) want to be stored in the same database table. Most of the fields are identical, with each subclass adding 1 or 2 custom fields. My code is using ...
0
votes
2answers
54 views

Anti-pattern or acceptable way of using Promises? [closed]

Whenever I need to use a Promise interface in my NodeJs code and I don't have a promise to start off with, I do this: ...
1
vote
0answers
38 views

Visitor Pattern in Ruby

After reading about the Visitor pattern, I wrote this example in Ruby, loosely based on a Java implementation on the wikipedia page. The choice between modules and classes felt somewhat arbitrary for ...
0
votes
3answers
108 views

CRUD strongly typed data access

I have a data access class: ...