Tagged Questions
11
votes
4answers
174 views
More German overengineering™ - Class mappings and factories
Goals:
So the plan was simple: Provide a factory to instantiate implementations of a certain interface (ModelConverter<T>), depending on what model-class you ...
0
votes
0answers
24 views
Find POJO by one field in List [closed]
I often find myself having to write helper functions like these
...
1
vote
1answer
38 views
Extend or Encapsulate [closed]
I couldn't find proper tips anywhere, since searching for these general terms isn't very efficient.
I deal with this almost everyday, creating Java SWT widgets in particular.
Each time I create a ...
3
votes
0answers
40 views
Is this a valid implementation of the MVP pattern?
Since fxml controllers compromises pure MVP, I tried to implement the pattern in this way:
Main presenter class:
...
5
votes
3answers
98 views
Confusing control flow
Currently, the following code runs and produces the expected and desired output. However, I'm sure that there's much wrong with it.
This project queries the (flat) database, instantiates each row as ...
3
votes
1answer
45 views
Refactoring this producer consumer class to minimize what is exposed
I don't like the service class below, specifically, the way it exposes the internals of the producer. While it would be possible to combine all three classes into one producer-consumer, I would ...
7
votes
1answer
145 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
48 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, ...
3
votes
2answers
62 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
200 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
102 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
106 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
107 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
748 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
36 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
117 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
186 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
128 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
50 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
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:
...
17
votes
6answers
647 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 ...
8
votes
2answers
112 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
484 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
183 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
105 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
86 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
126 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
162 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
154 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
64 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
248 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 ...
6
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
526 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
283 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
101 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
151 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
144 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
282 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
270 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
75 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
160 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
761 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
240 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
677 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
111 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
258 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 ...
5
votes
2answers
142 views
Note class for managing information on various musical notes
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
258 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 ...