Tagged Questions
0
votes
0answers
23 views
Outsourcing substeps to helper classes [on hold]
I understand that the following is a broad question. In my opinion, code quality is very subjective and healthy discussions are an effective way to share knowledge.
When a class performs a ...
7
votes
1answer
129 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
43 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
48 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
196 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
98 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
105 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
102 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 ...
1
vote
1answer
122 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 ...
11
votes
3answers
391 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 ...
3
votes
2answers
116 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
...
0
votes
1answer
31 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 ...
10
votes
1answer
162 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
115 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
48 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 ...
17
votes
6answers
644 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 ...
2
votes
2answers
180 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:
...
10
votes
5answers
478 views
Optimizing boolean checking method
I have written a method that checks if n number of true booleans are present in a ...
9
votes
2answers
111 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 ...
2
votes
2answers
601 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 ...
1
vote
1answer
58 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 ...
3
votes
1answer
165 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 ...
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 ...
5
votes
2answers
98 views
Better way to overload/implement these logging methods?
I got really tired of having this code in all of my classes and methods:
...
7
votes
1answer
119 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 ...
3
votes
2answers
167 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 ...
10
votes
2answers
277 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 ...
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
152 views
Handling null arguments in a factory class
I have a Factory class that gives out instances of ResponseImpl class. It accepts one ...
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 ...
3
votes
1answer
263 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 ...
2
votes
4answers
461 views
Using Java's instanceof operator
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 ...
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 ...
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 ...
3
votes
2answers
639 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 ...
2
votes
1answer
221 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 ...
7
votes
1answer
134 views
Returning a list of objects
Please review the following code. Methods getFirsts and getSeconds, both of which are ...
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
2answers
2k views
Pattern Against Anemic Domain Model
I would like to solicite 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 ...
3
votes
1answer
746 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, ...
8
votes
3answers
472 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 ...
5
votes
1answer
238 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
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 ...
3
votes
2answers
97 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
144 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
273 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:
...
2
votes
4answers
159 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 ...
10
votes
1answer
2k views
Multiple Inheritance and Composition with Java and C# (Updated) [closed]
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 ...