Tagged Questions
7
votes
1answer
121 views
Unit conversion activities
Please review these activities which handle converting units in an Android app:
I would appreciate any guidance and advice on code refactoring and different design patterns or strategies that I ...
3
votes
1answer
40 views
An attempt to extend an enum to prevent branching without violating the Open-Closed principle
I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, ...
2
votes
0answers
40 views
Abstract factory pattern implemented in Java
I need a code review on my Abstract Factory pattern written in Java.
Find the two enums AnimalType.java and DietType.java below.
...
1
vote
2answers
194 views
Code duplication for just an if condition
I have two methods that are near-perfect duplicates. There is of course a code smell. The only thing that changes is the condition to increment a variable.
Language: Java7
...
5
votes
3answers
96 views
Use of mediator design pattern with mailing list implementation
I have implemented the following scenario for the Mediator pattern sample:
MailingListMediator: Manages the subscription and send the mail back and forth.
...
2
votes
2answers
104 views
Refactoring conditional statements among different classes
I wonder there is any method of refactoring nested condition. It's just the same content with different contents and different classes which looks bad. I really want to reform this code which looks ...
6
votes
2answers
98 views
Create and organize some classes (hierarchy)
I'm trying to figure out what is the best way to create some objects in my application. The application is already running, but I want to structure things well and clean.
These objects represents ...
11
votes
3answers
317 views
Validate and import data from an Excel file
I have recently designed a module which will do bulk upload for different contents. Basically the user will upload an Excel file, I will have to read and validate headers of excel then each value of ...
0
votes
1answer
29 views
Where the validation should be done in a 3 layers Entity-Repository-Service application? [closed]
I am struggling to define where the validation process would be better placed in the different layers of the application? (I am not talking about user input validation here, I'm really talking about ...
3
votes
2answers
115 views
Is this an acceptable implementation of the Adapter pattern?
I've used the UK Plug -> US Socket and US Plug -> UK Socket analogy. I've also made it possible for UK plug to use a UK socket and a US plug to use a US socket. The output of the SSCCE below is
...
10
votes
1answer
157 views
Markup calculator application using MVC
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 ...
3
votes
2answers
107 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 ...
3
votes
1answer
47 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 ...
2
votes
2answers
179 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
643 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 ...
9
votes
2answers
110 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 ...
10
votes
5answers
477 views
Optimizing boolean checking method
I have written a method that checks if n number of true booleans are present in a ...
3
votes
1answer
160 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 ...
5
votes
2answers
93 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
84 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 ...
7
votes
1answer
114 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 ...
6
votes
3answers
157 views
Factory for classes unknown at compile time
I have a class called Machine. It contains a list of parts and a list of actions. The list of parts will contain instances of the ...
12
votes
4answers
833 views
Better way to manipulate this string in sequence?
I am working on a small custom Markup script in Java that converts a Markdown/Wiki style markup into HTML.
The below works, but as I add more Markup I can see it becoming unwieldy and hard to ...
9
votes
2answers
150 views
Handling null arguments in a factory class
I have a Factory class that gives out instances of ResponseImpl class. It accepts one ...
2
votes
1answer
59 views
Design To Handle Multiple Similar Model Class
I am doing a web app for an event company whereby customer can access the website for a self-help instant quotation. Customer will choose the type of event, fill a form and expect an instant ...
2
votes
1answer
212 views
Very basic Context Free Grammar in Java
I wrote this program for an assignment, thus I had some requirements as far as the format of the cfg.txt file and some basic other classes that we had to use. Other than that, I am curious if there is ...
5
votes
2answers
2k views
Generic DAO written in Java
I initially thought that this was just an architecture issue so I placed it on programmers as Thoughts on refactoring a generic DAO. Then I asked on codereview meta here and decided to put up the code ...
8
votes
3answers
454 views
Validation class to avoid ugly if-else blocks
I've answered this question on Stack Overflow. The problem is - there are 30 columns in an Excel sheet and I need to validate each of the fields with different validation logic. The code should avoid ...
10
votes
2answers
274 views
Date Format provider
I am facing a issue with an API to handle dates in Java. I am not a very experienced programmer and my English is very bad.
Problem
I'm working in a large project with many subsystems, and I want to ...
3
votes
2answers
96 views
Method Of Retrieving Random Value Depending on Type
I was wondering what would be the most appealing way of achieving this goal.
I have a blackbox. I give it a supported type and it returns a random value base off ...
2
votes
1answer
143 views
Singleton has logic and state, and logic has state
------edit---------
note: this is for a MUD client, so the commands are issued to the MUD game server
-----end edit--------
For an overview, here's the structure of the project:
...
2
votes
1answer
141 views
is this producer-consumer implementation correct?
I want to ensure that, as much as possible given my skill level, that I'm using relevant patterns correctly and following naming conventions. This is a controller for a poor-mans MUD client using ...
3
votes
1answer
269 views
How to implement a dynamic temperature conversion method based on given enums? [closed]
I am making some basic temperature conversion methods, and I want the end result to look something like this:
...
3
votes
1answer
262 views
A parent class, a singleton subclass, and a subclass uses a builder [closed]
There are three classes and an interface. The parent class is called MobileSignal. It contains info about mobile signal. E.g., CID, LAC, device ID, MCC, user ...
1
vote
1answer
74 views
Removing redundancy from an immutable “rules class”
I am writing a board game program in Java. Slightly similar to chess or civilization in that each player has a set of units, and each unit has certain actions that it can take.
The base ...
2
votes
4answers
158 views
One or multiple classes? Better-looking way to create tetrominoes in game
Background
A few weeks ago, I started working with Java. To get more familiar with the language, I decided to make a Tetris clone.
So, as I finished the Tiles ...
3
votes
1answer
740 views
TicTacToe - introduction to MVC pattern
After reading about MVC pattern in Head First Design Patterns, I've decided to write a TicTacToe app.
I will not reveal the source code of the classes Matrix, ...
5
votes
1answer
235 views
First introduction to MVC
I'm not sure that I fully understand this pattern. I've written a simple application that uses MVC. Please criticize my approach to the use of this pattern. For convenience, I'll post the source code ...
2
votes
2answers
566 views
Mocking utility class for database testing
I have these classes that have a boilerplate way of initialization. So, instead of writing it each time, I wrote a class called MockUtil.java, and I put the ...
6
votes
2answers
5k views
Chess board representation in Java
I'm currently working on a small chess game written in Java. The board is modeled as a Board object with a 2D array of Piece objects :
...
0
votes
1answer
110 views
PLease review code plus modularity and oops concepts
I had already posted question about the one i am asking right now Email report generation from database , to quickly revisit the scenarios I have trying to generate reports which have similar ...
7
votes
1answer
249 views
Design pattern review: freeze/thaw (aka, “reversible builder” pattern)
OK, this question may seem a little strange at first; however I'd like to have your comments on it.
Background: I do Java. A lot. Java is a statically typed language, it has means to restrict ...
4
votes
2answers
136 views
Does this violate the SRP?
I just finished (re)reading Clean Code, and one of the ideas I learned was the SRP. However, I am not quite sure on what defines a "Single Responsibility." In the piece of code below, I have a ...
1
vote
2answers
243 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
93 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.
...
2
votes
3answers
548 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 ...
3
votes
1answer
281 views
Review of simple Java Actor library
How can I improve this code?
Also available from git://github.com/edescourtis/actor.git .
Actor.java
...
-2
votes
1answer
159 views
Please review my switch case code [closed]
I have an enum param and want to do something according to its value.
While the enum param is too much and my method will become too long, how can I refactor my code?
I know that the refactoring ...
0
votes
1answer
169 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:
...
3
votes
2answers
164 views
Null Object pattern with simple class hierarchy
I have a simple two-class hierarchy to represent U.S. ZIP (12345) and ZIP+4 (12345-1234) codes. To allow clients to allow both types for a field/parameter or restrict it to one type or the other, the ...