Tagged Questions

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

learn more… | top users | synonyms

0
votes
0answers
8 views

.NET - multiple DLLs and one namespace

Please have a look at the code below: ClassLibrary1 has a structure as follows: Namespace com.app.test Public Class Class1 End Class End Namespace ClassLibrary2 has a structure as follows: ...
3
votes
2answers
62 views

Is this a correct way to use Factory Pattern?

I have an abstract class which implements the IDataCreator interface: public interface IDataCreator { public String getDataString(); } public abstract class AbstractCreator implements ...
-1
votes
0answers
32 views

Which pattern(s) are applicable for a form which opens in a different modes with minor changes? [closed]

Which pattern(s) are applicable for a form which opens in a different modes with minor changes? Mode 1 changes: Add a button that performs additional operation Mode 2 changes: Runs an additional ...
0
votes
1answer
53 views

Appropriate separation of concerns for this case?

This is a method that calls a web service, it uploads an audio file and fetches metadata back. While the advantage is that there is only one method to call there are a few concerns about it : There ...
-1
votes
1answer
85 views

Should I use inheritance in my case? [closed]

UPDATE - I write in C#. The code is added below. I have 2 classes that should run a service when calling their Start method, but before it they should: Copy items to F folder Open S service in ...
1
vote
2answers
53 views

Reduce JavaScript code. Double event, selector into one

Any idea how to write this code better."the html is nested tabs" Two selectors and two similar events, in a function would be better or a pattern to reduce lines. eg .jsbin $(function() { var ...
0
votes
2answers
59 views

PHP MVC simple sign up form review? Please be honest :)

I have tried to build my first MVC sign up form here is the code. Here is the user controller method register. public function register() { if($this->isPost()) { $user = new ...
2
votes
1answer
64 views

Observer pattern in Java

I'm going to have a lot of integer values, and at any value change I might need to update any number of UI elements, other values which are computed from the first ones, etc. Sounds like time for the ...
3
votes
1answer
63 views

Challenge: solution for this deep-iteration JavaScript function dilemma?

Trying to implement a deep-iteration function with some constraints, I've noticed the faster solution is iterating it twice! Any attempt to avoid this resulted in slower code. So, the challenge: can ...
2
votes
0answers
38 views

Are Request/Response Parameter Wrappers Good Practice? [migrated]

I've seen several different ways to design WCF services, and it seems some developers prefer parameter wrappers while others favor 'naked' parameters. To explain what I mean, consider the following ...
2
votes
4answers
120 views

Designing a better logger class

Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or ...
0
votes
0answers
25 views

Javascript Generic Components with Kineticjs shapes

I am planning to create an application to create software mockups. It will have some different elements but with similar behavior (like windows, buttons, menubars, etc), so I am planning to use the ...
-1
votes
0answers
46 views

Improve Design of this Java Application [closed]

I completed a group assignment for a Java course, but due to deadlines I was unable to really make it as clean as I wouldve liked. Since its over now and I have submitted the assignment I would like ...
5
votes
4answers
210 views

Which is considered better: push(array,value) or push(value,array)?

This is valid for many other functions. get(array,key) or get(key,array) ? find(array,value) or find(value,array) ? Etc...
2
votes
1answer
74 views

Am I using Golang concurrency correctly to increase reliability?

This code takes text from the standard input, maps it to a struct (if possible), and creates a JSON string from that. I'm using a barcode scanner for the input, and I've attempted to use goroutines ...
2
votes
0answers
57 views

Design Pattern for Swing application

I have a Swing application with no real design pattern. I want to start learning to design Swing or any types of application properly. Here is the main JFrame class. import java.awt.Component; ...
4
votes
2answers
103 views

Strategy Design Pattern in Python

I'm reading the awesome Head First Design Patterns book. As an exercise I converted first example (or rather a subset of it) to Python. The code I got is rather too simple, i.e. there is no abstract ...
2
votes
2answers
80 views

JavaScript event handlers, scope, and the module design pattern

I've been using JavaScript for some time now, but mostly just jQuery to prettify web pages. I've started doing some serious development with it in the last year. So, I want to make sure I'm not ...
4
votes
2answers
75 views

Move object by one up or down algorithm in a custom order

Basically, I did an object (using hibernate) with a field called sorting_order. This field needs to be unique and I wish to swap two object by one. So one element has to be after or before the current ...
3
votes
1answer
65 views

Python/Django Script - Is it crap? Objects duplicated or passed?

I've written a script using the Django ORM to store 'configuration settings' and interacting with the Google Drive API and another API. The script creates a base project folder and subfolders in ...
0
votes
1answer
48 views

Instance of one class to contain arbitrary number of instances of another class in Python

I'm trying to see if there is a better way to design this. I have a class Animal that is inherited by Male and Female classes (Female class has an additional attribute). I also have a class called ...
1
vote
2answers
57 views

How to implement Publish-subscribe pattern in PHP?

I have two classes, Database and Logger. Database is responsible for handling SQL queries, and Logger logs messages to an external file. Whenever the database executes an SQL query, I want Logger to ...
0
votes
1answer
70 views

Add behavior to existing implementation

My current implementation for service and business layer is straight forward as below. public class MyEntity { } // Business layer public interface IBusiness { IList<MyEntity> GetEntities(); } ...
1
vote
2answers
58 views

Populating a class whose data is stored in an external application

Im currently working on a system that will communicate with other systems via webservice (or some sort of communication). I have a system that stores all user data already and don't want to duplicate ...
2
votes
1answer
81 views

Using AbstractFactory

I am a newcomer to design patterns. I read some articles about the abstract factory pattern, and wrote the following simple example: public interface ParserFactory { List<ITransport> ...
1
vote
1answer
39 views

Access to a pimpl's members from another pimpl

I am writing an audio engine that must be multi-platform (win/linux). Basically, a CSound represents a sound file, and CSoundInstance represents one playing of a CSound. Obviously, playing sound is ...
-1
votes
1answer
72 views

design classes for a JAVA swing application [closed]

I am very new in making JAVA swing applications.. My problem statement is to make a library management application,for which i designed classes as below. Please tell me whether my design of classes ...
0
votes
1answer
45 views

Using closure, alias and namespace extension patterns: How to allow for independent instantiations of plugin?

Simplified working demo code here. Relevant JS code: ;(function(exports) { //-------------------------------------------------------------------------- // // Private properties: // ...
1
vote
1answer
47 views

Pattern for creating a JavaScript plugin

I 'm currently using this pattern to create and extend a globally accessible custom plugin to be used in a web application: ; // defensive programming: script may be concatenated with others ...
6
votes
3answers
321 views

FactoryPattern without If-else construct

Someone asked me if I can create factory pattern in java without using If-else construct. So I come with the following. Please provide your inputs if this seems a good example for using factories. ...
1
vote
3answers
51 views

Factory Method Pattern - Is this example correct?

Can someone please confirm if below example has properly implemented Factory Method design pattern? If not then please suggest necessary modifications. #include<iostream> using namespace std; ...
2
votes
1answer
50 views

Content Management System Design Pattern Opinion

I am building game platform content management system where i have the following classes: Game, GameReview, Video and so on... Every Game object has list with GameReview objects and every GameReview ...
1
vote
3answers
80 views

Do you think this design pattern is good for game portal content management system

I am developing game portal content management system using java and j2ee tehcnology. However i am stuck in my design implementation. Here is the scenario: Each Game object has attributes like id, ...
2
votes
1answer
100 views

The Observer design pattern in Python in a more pythonic way (plus unit testing best practices)

I'm continuing to work on the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is here with ...
6
votes
1answer
244 views

How can I make this C# code better so it more closely follows DDD principles? Am I using factory correctly?

I've been working on converting some legacy code from T-SQL stored procedures. My aim is to use DDD to make the transition. Below is an attempt to do this. Any comments on how well this is following ...
1
vote
1answer
62 views

proxy pattern in Python

This is my try at the proxy pattern. What do you Pythoneers think of my attempt? class Image: def __init__( self, filename ): self._filename = filename def load_image_from_disk( self ...
2
votes
1answer
154 views

The Strategy design pattern for Python in a more pythonic way

I've recently picked up the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Unfortunately, the code examples in this book are in Java. I'm not the ...
0
votes
2answers
74 views

Repetitive code for different Database Entities with same implementation

I have this code in LogInService public User isValid(User user) { if(user == null) return user; User db_user = userDao.getUserByUsername(user.getUsername()); if ...
1
vote
1answer
76 views

I inherited legacy code which calls tries to lazy load in every properties getter. Is there a pattern I could apply to this to clean it up?

I've inherited a class which has a bunch of properties defined as: public int ID { get { return m_nOID; } set { m_nOID = value; } } public int ConxnDetail { get { LoadDetails(); return ...
0
votes
1answer
118 views

Review algorithm of this code

In this piece of code i have to display some set of data in serpentine order.In an experiment there are Replication,range,plot Replications contain range,plot.A range contains plot. if there is 2 ...
0
votes
2answers
120 views

Review code for optimization and implementation

The below code does Read csv files and process it to do some sort of cacluations.This is more of small picture code , to introduce big picture. The csv file contains information of seeds of crop which ...
2
votes
1answer
119 views

Have I implemented the command pattern correctly?

This is my command interface public interface IConverter { void convert(); } This is my Receiver class public class Ogg extends Audio{ private File src; private File trgt; ...
0
votes
1answer
38 views

Actionscript 3.0, good OOP?

I have been coding for some time (3 years I think), and have recently been wondering if my coding pattern is any good. Any kind of feedback is welcome: EDIT: The thing that concerns me most is that I ...
5
votes
3answers
246 views

Does this ugly code fit into a design pattern?

I'm trying to figure out a pattern to best accommodate this pretty ugly code: var userDiscounts = _discountRepository.GetUserDiscountsForUsersWithDiscounts(new List<int> { buyerUserId, ...
0
votes
1answer
120 views

Redesign a module to be generic

I am having trouble designing a module, can anybody help me? Because it will be hard to maintain this kind of module, I also think that this can test my skill of design pattern usage. Requirement ...
1
vote
1answer
59 views

Command design pattern: different implementations

I learned about the Command Design pattern and saw different implementations of it: 1: Receiver receiver = new Receiver(); Command command = new ConcreteCommand(receiver); Invoker invoker = new ...
1
vote
1answer
97 views

JPA connection : is this code is efficient enough

By reading some tutorial i have written some peace of code to do crud operation . I just want to know how is this code is efficient or how can i make better ? Here i am giving code of 3 class 1. ...
1
vote
1answer
94 views

Factory pattern for getting xml data

i am trying to implement factory pattern for getting XML Document from server (using javax.xml.parsers.DocumentBuilder) I have the classes below for now, could you give your opinion ? Does the ...
1
vote
3answers
113 views

Am I getting the builder pattern right?

Despite being the clever Java coder I am, I noticed I know way too little about various design patterns. The builder pattern caught my eye as something to learn, as I have certainly seen my fair share ...
3
votes
1answer
168 views

Optimize PHP Class

I'm looking for a better way to provide configuration options and improvements in general. I'm using the constructor injection pattern to get access to the Cache and Twitter class. $callback and ...

1 2 3 4