Questions tagged [design-patterns]

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

Filter by
Sorted by
Tagged with
5
votes
1answer
5k views

Singleton class extending a parent class to utilise shared functionality

I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared ...
5
votes
3answers
22k views

ASP.NET MVC using Repository pattern

I am just trying to use ASP.NET MVC using repository pattern. Am I doing something wrong here? Model - Contains the model ...
1
vote
1answer
144 views

Class which updates an object

I have a class which updates an object. The class takes a String id in its constructor and returns the appropriate class based on the ...
2
votes
3answers
2k views

A simple php Session class, is the layout/design correct?

Basically I'm writing a simple framework in php in order to learn more. This session class is extremely rudimentary. At this point I'm not even checking ip/user_agent to prevent session hijacking, it'...
3
votes
1answer
1k views

Providing factory method to Lazy<T> when factory exists on another lazy instance?

The Problem I found myself needing an instance of an IObjectContext interface that should never be null, but wanting to delay instantiation until after some ...
6
votes
1answer
327 views

Does this code fall into a design pattern?

CustomDialog is the parent abstract class for OkExclamationDialog and ExclamationDialog with ...
10
votes
3answers
646 views

Is this correct factory method pattern?

I know that there are many similar questions, but I don't understand most of those questions because I'm not sure if I know what a factory method pattern is. So, after reading many examples over the ...
4
votes
3answers
2k views

How to simplify my data access or shift it into an ORM

In building any new application I end up using something similar to this data access type code. I know it well, and it works well. But in the act of wanting to try something new on a new project I ...
5
votes
1answer
4k views

C# Multi level HTML TagBuilder object - Design pattern Review needed

I find the TagBuilder written in C# little poor without the ability to "host" inside it sub tags (as objects not as strings). So I wrote a simple class that inherits TagBuilder and allow to save sub ...
10
votes
1answer
4k views

What do you think of my EventAggregator implementation in C#?

I was looking for a simple Event Aggregator to use in my app, but I found people get very complicated very quickly, so I thought this was easy enough to write myself. It seems to work, but I was ...
5
votes
1answer
723 views

What do you think of this chained producer/consumer/adapter (pattern?)

If I had many different Models that could all, through logic encapsulated by an adapter, produce items of type T, then I might maintain a producer/consumer component through the techniques ...
8
votes
1answer
3k views

best design pattern for refactoring a set of classes that do calculation base on many parameters

I'm refactoring a set of classes which does some price calculations. the calculation is done based on many parameters. The code is : ...
5
votes
1answer
128 views

Module for making a doubly linked list

This module makes a doubly linked list and initializes each member. I couldn't do it with a loop, so I gave up and made each node individually. How can I improve it? Can somebody help me make a ...
5
votes
1answer
536 views

Is this an appropriate class design for the strategy pattern in Ruby?

I am fairly satisfied with my solution here but I would definitely appreciate any constructive criticism of my style and design. The basic idea is to use the strategy pattern to simplify assembling a ...
0
votes
1answer
667 views

Composite Design Pattern in Scala

The following is a personal attempt at implementing the Composite design pattern in Scala. Observation is abstract... ...
4
votes
3answers
148 views

Adding push to array inside the class that is being pushed

I used to mostly do this: ...
1
vote
1answer
836 views

Refactor IF into Chain of Responsibility Pattern

I've been trying to learn different patterns of programming, and the "Chain of Responsibility" sort of eludes me. I've been told that my specific code snippet would be a good candidate for chain of ...
2
votes
1answer
2k views

Advice on approach to organizing my business logic & data access? [closed]

I've been researching various patterns for structuring my business logic & data access, particular in the context of C# and the Entity Framework. I've come up with a basic idea of how I think I'd ...
2
votes
2answers
954 views

JavaScript MVC - review and suggestions

Before I start working on a quite JavaScript heavy application I would like you to review my JS MVC approach. How can it be improved? Are there any mistakes/issues I should be aware of? Since the ...
5
votes
3answers
1k views

Simple PHP Auth Class feedback

this is a basic PHP auth class I've put together for use with simple sites I do from time to time which don't warrant using a framework. I'm wondering if i'm separating out responsibilities all that ...
11
votes
1answer
2k views

Component-based system for JavaScript game

I'm creating a JavaScript/WebGL based game and would like you all to take a look at the current entity component system which I created for it. I've used it once before on another project, and while I ...
9
votes
1answer
5k views

Generic C++ Factory

For my project, I needed a way to instantiate different object types during runtime using "string names", for this I designed a generic factory that is created for each object hierarchy type (...
2
votes
3answers
2k views

Variations of the Repository Pattern

I've been using this variation of the Repository pattern for over a year now: ...
5
votes
3answers
2k views

Simple DI container

I'm building a web application and is trying to make my code reusable. I've decided to create components that can be used outside this project. Now I'm trying to create a simple DI container, one ...
8
votes
1answer
501 views

Use of external memory or a custom allocator

I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a ...
3
votes
3answers
768 views

Email text validator

I'm using this pattern for the first time and wanted to check if this is the correct implementation. class.validator.strategy.php ...
7
votes
3answers
6k views

Sales tax calculator

Please review the sales tax problem which has been designed using strategy pattern. The Problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical ...
3
votes
4answers
4k views

Iterator pattern/iterator class

I have implemented a simple iterator. Just want to check if I have missed anything. ...
4
votes
3answers
267 views

I want a nice design pattern for “All”, “many” or “one”

In my particular usage here, I'm using two functions to deal with one thing. Lets say the user request comes in to select "ALL" the records, in which case I would pass on some code such as: ...
0
votes
1answer
2k views

How to re register dynamic scripts registered with ClientScriptManager in asp dot net using session was bad idea

Following the normal pattern of adding inline scripts to gridview row/s is a bad practice it used to work like below ...
5
votes
3answers
391 views

Improving the design of this program.

I am trying to design a program that will read a XML file and based on the tag name will perform certain requirements checks. I feel that there is probably a better way of doing this and any comments ...
12
votes
1answer
599 views

Utility functions for supporting memoization for functions

I've got a couple of utility functions to support memoization for functions with anywhere between 0 to 8 arguments: ...
6
votes
3answers
839 views

Tetris clone in Java

I have a representation for each initial shape as an Enum with points and another for each rotated shape in the same Enum. Here ...
5
votes
4answers
3k views

Is this architecture overly complex or following best practices?

I work as a C# developer at a company that doesn't use best practices at all. We're on .NET 3.5 but most code is written in a .NET 1.1 style (e.g. almost all the logic is in the code behind of the ...
11
votes
4answers
3k views

Composite and Visitor patterns for tree-based survey functionality in C#

I have written some survey functionality for a project. Basically, a generic survey form that can be composed of sections and questions. I have a Survey class, <...
9
votes
3answers
568 views

Are these endless if statements a bad pattern?

I'm only asking because almost the entire code base I've inherited here, in C# and PHP, looks like this: ...
5
votes
2answers
4k views

MVC Controller in Java Swing Apps - Singleton or public static

This article has left me a little confused. In explaining a method on how to design MVC into Java Swing apps the author defines the controller class as Singleton and relays a series of calls to the ...
6
votes
2answers
1k views

python object pool with metaclasses

...
6
votes
3answers
806 views

IEnumerable of classes that implement a given interface at runtime

I am implementing the command pattern in a project that I am working on and I have an interface, ICommandFactory that all of my commands are implementing. When I ...
4
votes
1answer
208 views

Sorting Visitors

I started to write a code with top-down tests. My first version, grow to something like this: ...
7
votes
1answer
6k views

Hypothetical SalesTax challenge

I have a small solution to the following hypothetical problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty ...
11
votes
3answers
2k views

Pattern Against Anemic Domain Model

I would like to solicit advice on everyone's thoughts on how best to combat the Anemic Domain Model anti-pattern when building out a system based on web services. One of our goals is to build a set ...
24
votes
4answers
13k views

Interface for unit of work pattern and repository pattern

I'm trying to design a well defined yet simple interface for the unit of work and repository patterns. My UoW's are exposed to services and services then "get repositories" that it needs to query. I ...
23
votes
4answers
2k views

Law of Demeter and data models?

Inspired by this question, but hopefully not a duplicate. I understand that the Law of Demeter is very useful in case of services interacting with other services, for example it's much easier to mock ...
23
votes
5answers
17k views

Best way to pass parameters to Factory class?

So I have a series of objects, which I will call Impl1, Impl2, and Impl3. They each implement an interface, called IImpl. I have a Factory class who's task is to retrieve the ImplX which is ...

1
21 22 23 24
25