Tagged Questions
1
vote
2answers
78 views
Email report generation from database
I have written a small batch job which will collect data from db and send mail to user. Can you please do a review of the code with design prinicples in mind and also with best practices for Db and ...
2
votes
2answers
68 views
Converting string with a lot of if statement
I have code like the following one, which I use to convert string to another string.
public String convertString(String string) {
String convertedString = string;
if( string.contains("something")) ...
2
votes
3answers
93 views
Design Strategy of CSV Parser
I wanted to review my design strategy for CSV parser.
I have 4 CSV files, which have different layouts as shown below.
Each row of a CSV file will be mapped to a class. For example, if CSV_FILE_A has ...
2
votes
1answer
99 views
Review of simple Java Actor library
How can I improve this code?
Also available from git://github.com/edescourtis/actor.git .
Actor.java
package com.benbria.actor;
public interface Actor<T> extends Runnable {
public ...
-1
votes
1answer
114 views
please review my switch case code
Now I hava a enum param and wants to do something which is acording to the enum param value.
While the enum param is too much and my method will become too long.How can I refactor my code?
I know ...
0
votes
1answer
68 views
Q&A system model design [closed]
Now I am trying to build a Q&A website by myself.The models below is my model design.I have some questions about this.
1、class Category:
public class Category {
private String name;
}
...
0
votes
1answer
61 views
how do I encapsulate this List<Message> properly?
I know that Swing isn't true MVC:
Using this modified MVC helps to more completely decouple the model
from the view.
Leaving aside the veracity of the above claim, the problem I run into is ...
1
vote
1answer
36 views
Opinions on my Command pattern design - is it extensible?
I am implementing a program that takes commands from a user and based on those commands, drives a Robot on a grid. To implement this program I have used the Command pattern. I have used this pattern ...
0
votes
0answers
33 views
immutable metadata constructor access
I want an immutable class, and the constructor should be package private. However, it ends up getting used outside the package:
package gnu.mail.providers.nntp;
import gnu.inet.nntp.GroupResponse;
...
1
vote
0answers
22 views
Is this a good approach for a BayeuxClient class?
Is this a good approach for a BayeuxClient class?
Reading cometd reference book, Chapter 6 Java Libraries, I created this BayeuxClient class.
As a newbie to cometd, I would like to know if this ...
4
votes
2answers
144 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 ...
2
votes
1answer
83 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 ...
2
votes
1answer
87 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
105 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 ...
2
votes
1answer
86 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
votes
1answer
108 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 ...
6
votes
3answers
345 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.
...
2
votes
1answer
59 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
87 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, ...
0
votes
2answers
79 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 ...
0
votes
1answer
125 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
125 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
131 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
123 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
145 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
104 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
129 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
2answers
163 views
Change View visibility programmatically or through XML?
I have an XML layout used by 2 activities. Within this layout, there's a view that is visible for Activity1 and gone for Activity2. Activity1 is used more times compared to Activity2. I would like to ...
1
vote
4answers
195 views
Java using instanceof operator for this example
I am developing a BlackJack game using Java, and it came to a point that I am using instanceof operator to determine if it is a type of some subclass.
Here's an example.
public void ...
5
votes
1answer
104 views
Please review following code
Please review the following code. Methods getFirsts and getSeconds return a list of objects which implement CommonInterface and both of them are private. Is it a good or bad design.
@Override
public ...
2
votes
1answer
86 views
Is my DSL good idea to replace builder pattern?
I want to build a set of builders for generating test data. On one side I want my builders API to be natural to use for my teammates. On the other side I'm great fun of creating DSLs, because it ...
4
votes
1answer
139 views
How to improve this design?
I have some design doubts regarding my controllers and I would like some advice...
Everything works. However, I'd like to improve it.
Basically I have one controller per screen(Swing).
I have created ...
2
votes
2answers
100 views
Is there a cleaner approach to matching class types in this observer like pattern?
I have written an implementation of the observer pattern that allows messages to be passed to listeners in what would normally be the notify() method. For example a subscriber sub-class might look ...
9
votes
6answers
677 views
Multiple Inheritance and Composition with Java and C# (Updated)
The following article explains the usage of the composition design pattern in environments that do not allow multiple-inheritance of classes. Note: All code examples are written in C#.
In Java and ...
1
vote
2answers
267 views
How to remove duplicate code in these two very similar Java classes?
I have two Java classes with very similar code. Basically they are almost the same excpept for a few method calls etc, i.e. replace 'ip' with 'msisdn' in the classes and they would be identical.
I'm ...
2
votes
2answers
196 views
Is this Sudoku a good use of the Fluent Builder Pattern?
Code
Sudoku.java
public class Sudoku implements ISudoku {
/**
* Generates wildcard values in case of conflict with the keys of the
* Sudoku. Ensures all characters are alphanumeric, ...
1
vote
1answer
148 views
Two related hierarchies of classes
In order to do its work, a DataProcessor needs Data and otherData.
One instance of Data will be shared over a set of DataProcessor,
but each DataProcessor has its own otherData.
For sharing Data ...
2
votes
2answers
161 views
How to use inversion of control within a strategy when using the strategy pattern
I am creating a skeleton application to demonstrate use of the Strategy design pattern and inversion of control inside a Strategy.
The application is the backend of a simple board game, which also ...
1
vote
2answers
200 views
Comments on my Java pattern for Mutable turned Immutable objects
Commenting omitted to give you the idea. I've been toying with this recently as a variant of the Builder pattern. I've recently fallen in love with immutable objects for the benefits they give in ...
2
votes
1answer
1k views
Knight's Travails solution
I created this as part of an interview process of graduate programming job. Submitted the code to them, and I was called for an interview.
This is the assignment brief: ...
3
votes
1answer
2k views
Correct DAO implementation?
This is my first go at implementing the DAO pattern - let alone implementing it for MongoDB with Morphia - I was hoping someone could point out smells and answer questions from my below ...
6
votes
5answers
357 views
Vegetable factory
I'm new to Java. I'm trying to build a simple hierarchy of classes.
abstract class Vegetable
{
public Vegetable(double weight)
{
this.weight = weight;
...
}
...
}
...
2
votes
1answer
4k views
Java Slick 2D Collision Detection Methodology
I have a collision detection for terrain setup (non-terrain is handled with a quadtree I implemented apart from this) and I was wondering how others have done it compared to mine and what I could ...
5
votes
1answer
672 views
Java Slick StateBasedGame managing resources across states
I was wondering if it's normal/efficient to have this many static collections in my state based game?
I started doing it for ease of access but it looks sloppy to me and I was just wondering what ...
4
votes
1answer
1k 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 scheduling functionality. A thread is ...
0
votes
1answer
96 views
Is this class doing too much?
I have a class which updates an object. The class takes a String id in its contructor and returns the appropriate class based on the ID. I think these two methods should be seperated into their own ...
5
votes
2answers
239 views
Does this code fall into a design pattern?
CustomDialog is the parent abstract class for OkExclamationDialog and ExclamationDialog with abstract method displayDialog() being overriden.
Does this fall into a design pattern? Can this design be ...
2
votes
4answers
1k views
Iterator pattern/iterator class
I have implemented a simple iterator. Just want to check if I have missed anything.
interface iterator<E>
{
boolean hasNext();
E next();
}
class Iterator<E> ...
4
votes
3answers
366 views
Enum overkill or not?
I am developing a 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 is an example of the latter ...
4
votes
2answers
2k 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 ...