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

learn more… | top users | synonyms

2
votes
0answers
35 views

Improving a system calculator application

I want to make sure that the code is correct in terms of its design, code correctness, best practices & Junit testing. The complete description is given below: **Functioning of the app quickly ...
2
votes
1answer
60 views

Is the following repository pattern properly applied?

Is this repository code written according to best practices? The Last Section I included it in the repository as well. ...
0
votes
0answers
13 views

When to use service pattern? [on hold]

Im confused as to how to decide on where to place logic in a Service Pattern vs Class Object How do we determine when we need to separate logic into it's own Service Separated Section? Why not just ...
3
votes
2answers
70 views

Java implementation of the Factory Method pattern

I am working on a very simple game and thought it would be a good opportunity to learn and use the Factory Method pattern for creating game objects. I studied the pattern but I'm a bit confused about ...
-1
votes
0answers
26 views

Program Settings using Adapter pattern [closed]

I'm working on a program at work that is both a keyboard wedge and keyboard hook. I may have made a mistake on the two wedge configurations, but I have 1 wedge as a base which just takes a com port, ...
0
votes
2answers
107 views

Tic-Tac-Toe implementation where computer should not lose

I have implemented Tic-Tac-Toe so that human can play with the computer, where the computer should never lose. I did a simple analysis before implementing, and I found out that there are certain ...
4
votes
1answer
50 views

State Design Pattern in Python

I'm trying to find the best - read: readable, maintainable, robust, threadsafe, usable - solution for a State Machine in python. For this I've been looking at the State Design Pattern. However I want ...
0
votes
0answers
16 views

UnitOfWork vs Service Layer [migrated]

I'm getting into the Repository pattern (which I love), and as I read up on it I see this UnitOfWork pattern in many articles. Before I knew anything about UnitOfWork I was just using my Repository ...
6
votes
5answers
795 views

Project Euler #3 - largest prime factor

I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of ...
6
votes
2answers
165 views

Pattern to avoid Variable Functions?

I have some PHP code where I use Variable functions to call the right function. I need to build a chart array (for example), and the chart array that comes out has a fixed format. But the data that ...
3
votes
1answer
44 views

Is it correct to extend a bean class and write a class which holds logic to populate the bean we extend?

I need to extract some metrics from ManagedBeans and store the collected metrics in an object bean. The object bean is defined with member variables to hold the metrics. In this case, is it right to ...
3
votes
1answer
65 views

Redunancy Issues in PHP Class

I've been studying PHP for a while now and decided to dive into OOP. Most of my code was a mess and I've begun to refactor much of the website to OOP; however, I'm having an issue with redundancy in ...
2
votes
0answers
59 views

Implementing the Repository Pattern

I'm new to this pattern and I see arguments online about different implementations. I have the following code and it seems fine to me, but I'm wondering if having to pass the DBContext into the ...
2
votes
2answers
28 views

What do you think about this custom syntax? [closed]

I'm making a programming language and I've got the basis of a virtual machine working. The next step to is design the actual syntax for the language. I'd just like to know if whether the example ...
2
votes
2answers
168 views

Avoiding instanceOf when finding index of an interface within a list

I am working on some code and I have come across the following: ...
17
votes
6answers
622 views

A Library Class : Point

I am trying to create a library of my own which contains (among others), a class called Point. As the name suggests, it is intended to encapsulate a point ...
4
votes
0answers
35 views

Making a FileHandler more OOP friendly using SOLID

I have a class created for the sole purpose is to help handle files. The class holds a path(folder) that contains a single file at a time. Some extra properties to this class are: age of a file and ...
3
votes
0answers
37 views

jQuery Plugin - HTML5 History State

I've built this small jQuery plugin to work with HTML5 History State functions. It's my first jQuery plugin, so I'm not sure if it's up to the best practices, or what could be done better. Keeping it ...
3
votes
1answer
83 views

Searching text files for string patterns that are each defined in their own classes

I'm trying to implement interfaces in my design but not sure if this is correct or if there is a better way to do it. What I need to do is open a text file keep searching blocks of text until I ...
1
vote
0answers
32 views

Refactoring Data lookup table with Redis and API call

Background to the code: This class' function is to change a given array's data into an ID. The list is set by a configuration file. I have DI the outer array and objects into the class so that if ...
9
votes
4answers
144 views

JavaScript Good Patterns - Is this a good example?

I have been trying various formats of namespaces and modules patterns, however I have not come across a solution that I would use for all my projects. I've been developing the following, that would ...
3
votes
2answers
76 views

Simple design pattern for authorization in PHP [closed]

What do you think about the following class? Do you think it is a good approach to solve the authorization problem? I'm looking for a very simple design pattern. ...
4
votes
1answer
54 views

Structure a webapp using RequireJS

I've written a small webapp in JavaScript, and am now essentially rewriting it to use RequireJS. I'm doing this partly to get more familiar with RequireJS (which I have little experience with), as ...
5
votes
2answers
63 views

Simple factory of a complex object [closed]

I've got few doubts about factory pattern, so I'm looking forward for your review of the following two factories. I've heard that factories should have no state. But what about factories inside ...
2
votes
1answer
64 views

UnitOfWork as Repository object factory

I have done some research about intentions of UnitOfWork pattern. In short, what I understood is that UoW is needed for transactions. But I saw some code examples where people use UoW as factory for ...
6
votes
3answers
105 views

Advice on “Factory” Pattern Implementation

I'm refactoring some code around a couple of ASP.NET Web Forms pages and decided to try out a variation of the Abstract Factory pattern of my own design. I need to create an implementer of an abstract ...
4
votes
1answer
62 views

Should I create two seperate Services and then combine them or have one large?

Basically, I have two separate tables, Campaign and CampaignDetails. They relate via CampaignID. I want a service that can handle both at the same time, as they're closely related and when one gets ...
9
votes
2answers
97 views

Optimizing “simplifier”

Basically, I'm trying to make a Simplifier that can take inputs in the form of a String and print out the solution step-by-step. Now that I've got it working, I ...
9
votes
3answers
177 views

Listener/Observer Model in PHP

I've taken a look at the SPL Listener/Observer model but found that it doesn't work when using static methods. So I wrote my own but it's very simply. Can anyone suggest ways to make it more like the ...
10
votes
5answers
458 views

Optimizing boolean checking method

I have written a method that checks if n number of true booleans are present in a ...
10
votes
2answers
111 views

How can this Ruby format analyser be improved?

I have a requirement to validate file names related to architecture after they are uploaded. Once they have been uploaded I must warn the user if the file name is not standards compliant. What's in a ...
5
votes
2answers
104 views

PHP framework building: Sessions Managment Class

I am building a PHP framework and would like to get some feedback on a few different sections of the project so far. I consider myself still a neophyte in PHP so I would like to ask if I'm going about ...
4
votes
2answers
60 views

Is my simple string tokenizer wrapper orthogonal?

I always learn something from Code Review, so if anybody could point out any bad practices in design, violations of DRY, or orthogonality problems I would be extremely grateful! ...
3
votes
1answer
102 views

Java MVC pattern

I recently posted a question about modeling a system that contains elements that can perform actions (here). The model runs in cycles and parts perform their action every cycle. The model should have ...
2
votes
1answer
71 views

“Property Container” design-pattern

I've tried to write my Property Container design-pattern implementation. Could anybody, please, tell me, if this code is really what I intended to write (follows ...
7
votes
1answer
270 views

Simple example of N-Tier, entity framework, unit of work, repository, business logic layer

I've been studying C# for about 6 months and am trying to make a simple example for an n-tier application. I want to learn to do things in the most proper and professional way. This example uses a ...
3
votes
1answer
44 views

Is it a classical MVC (Xerox Parc) implementation?

I've been trying to understand the original MVC implementation (the Xerox Parc's one). I'm sure it has flaws, but it's a simple code to practice/learn the original MVC. Working example View ...
5
votes
2answers
67 views

Better way to overload/implement these logging methods?

I got really tired of having this code in all of my classes and methods: ...
4
votes
1answer
83 views

How to make business logic code maintainable when working with multiple states?

I am developing a UI Application for a very simple phone app, the UI is based entirely on the state of Call in a container provided to me by a third party library. Below is a sample Call object that ...
0
votes
0answers
28 views

Classes to iterate over millions of records, performing calculations and comparisons on each

I'm converting a PHP written with a lot of procedural loops to classes. There is a hierarchy of nested information represented in nested associative arrays. The actual records are from currency ...
6
votes
3answers
477 views

Lots of repeating code, trouble refactoring

I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail ...
2
votes
2answers
252 views

Singleton design pattern

I am a beginner in PHP-OOP and design patterns. I have got this basic piece of code in Singleton Pattern and I changed it in order to understand its behavior. I can see that it works as expected. ...
1
vote
1answer
47 views

Is this a model? What is controlling it (controller?) and how does the data get to the view?

My goal is to instantiate a class based on the request and call a method on it based on the request verb. The classes I'm referring to will have methods such as ...
2
votes
1answer
56 views

How to deal with some of the dependencies?

I am very beginning in PHP and Design Patterns. I have been studying the beautiful book "Head first: Design pattern" and I have been working in some of the codes originally presented in Java in order ...
3
votes
0answers
70 views

Is this a good PHP strategy pattern?

I am a very beginning in PHP and Design Patterns. I have been studying the amazing Head First Design patterns. So, I have been trying to translate the original to PHP. The class is working well. ...
2
votes
1answer
230 views

Repository pattern with plain old PHP object

I've been reading a lot about repository patterns these days. At first, the pattern seemed easy. Most of the examples I read over the web use an ORM like below. ...
2
votes
2answers
73 views

How to declutter dependencies?

I'm running into a problem with my code in a ASP.NET MVC application. Maybe it's not a problem and I'm just being paranoid, but it seems like a problem to me (might be because I've just read the book ...
5
votes
1answer
96 views

JavaScript Sandbox Pattern

Based on this Stack Overflow question I came up with the following code. I'd like your general thoughts about it. Code style, functional, logical, disadvantages, just anything you can come up based ...
2
votes
1answer
81 views

Are there any improvements I can make to my implementation of the strategy pattern?

I'm not sure about that if else statement in function Change(). I'm guessing there is a way to eliminate this and make better use of OOP principles. Does anyone have any suggestions? PS This code ...
7
votes
1answer
104 views

Model simulation using Java annotations

A couple of days ago I posted my code that models systems made up of moving parts. I got several great tips and ideas and here is my latest version. My actions are now methods annotated with @Action ...