0
votes
0answers
59 views

Separating UI from logic

I'm trying to develop a little game and for this I'd like to separate the UI from the game logic. So I'm thinking of using an "Animator" class that will be responsible for rendering the objects, but ...
2
votes
1answer
66 views

Is there a limitation when using the Bloch's Builder Pattern with mandatory fields?

Background I have a class TextDrawable which draws text on top of a shape. There are a number of properties that can be set while creating a TextDrawable object. Mandatory Properties: Text Shape ...
8
votes
3answers
611 views

Clean Code and Hybrid Objects and Feature Envy

So I recently made some major refactorings to my code. One of the main things I tried to do was split out my classes into data objects and worker objects. This was inspired, among other things, by ...
0
votes
1answer
62 views

Logic based on modified fields of a Hibernate entity

I have a Hibernate entity object MyObject with several attributes and a service MyObjectService containing business logic dealing with MyObject. I also have a view model dealing with user input/output ...
0
votes
1answer
112 views

When should I refactor a private class into a package-private class?

When I began implementing a class in my system (let's call it A), I realized I needed some kind of object that does something. So I needed a new class (let's call it B), but I made it a private static ...
0
votes
2answers
170 views

Handling multiple packet types in Java 8

I have a Netty-based game server implementation that handles 40 or so distinct packets with their own serialization structure, for brevity I'll refer to them as FooPacket, BarPacket, ... These packet ...
0
votes
3answers
143 views

How to change the state of a singleton in runtime

Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ...
1
vote
1answer
171 views

Design for object with optional and modifiable attributtes?

I've been using the Builder pattern to create objects with a large number of attributes, where most of them are optional. But up until now, I've defined them as final, as recommended by Joshua Block ...
0
votes
1answer
119 views

How to generalize a classes that has identical function plus some additional function

I have some designing problems with my project. To illustrate my problem, I'll use the following two classes from my project. public class RAM_UserManagement{ private Map<int,User> userList; ...
1
vote
3answers
198 views

Is it considered bad practice to make a DAO call in an object's constructor?

I am trying to figure out the best design for instantiating an object which requires two separate calls to the data layer through a DAO. The object is not usable until these calls have been made ...
3
votes
1answer
80 views

When to declare @throws with a Scala annotation - abstract parent or concrete implementation?

In this StackOverflow question I asked about the behavior of the @throws annotation in Scala. Now that I understand how it works I want to ask about best practices with using it. Here's a repost of my ...
2
votes
1answer
186 views

Builder pattern inside interface. Bad design decision?

I am having trouble evaluating an implementation of the builder pattern I just came up with. The context is an API library, so I am trying not to expose any implementations in order to have a stable ...
39
votes
9answers
4k views

Programming for future use of interfaces

I have a colleague sitting next to me who designed an interface like this: public interface IEventGetter { public List<FooType> getFooList(String fooName, Date start, Date end) ...
3
votes
2answers
107 views

System state design composition

Consider the following Java code: public class HumanStateImpl implements HumanState { private boolean alive; private Color skinColor; // getters and setters, other state fields ...
2
votes
1answer
204 views

How should object identification be managed?

I have a java/swing application in (hopefully good) MVC structure. Here is a overview of my model classes: One or more workers may work at one working location and one worker may work at different ...
0
votes
1answer
219 views

Object Oriented Design of a Small Java Game

This is the problem i am dealing with. I have to make a simple game of NIM. I am learning java using a book so far i have only coded programs that deal with 2 classes. This program would have about ...
2
votes
1answer
218 views

How to design the relation between a Game and a Player in a game?

I am currently attempting to make a Trading Card Game and I have got a whole array of features working already, yet I am stuck now at the portion where one player can attacker another player (more ...
2
votes
2answers
146 views

static set and non-static get method

I've the following Interface. public interface ValueInterface { long getValue(); } And the class: public class ValueCreator implements ValueInterface { private static long value = 0; ...
0
votes
3answers
116 views

Wrapping a map with instance or static method

I have a java.util.Map<String, Object> object which different types of values in it. I don't want to cast whereever I do a get operation over this. To do this, I created different classes ...
2
votes
1answer
198 views

Should we encapsulate everything in a try{} block in a Try object?

Why can't I make a class for a Try including what I try and then run that in the try {} block? Why is it impractical? class DBConnectTry extends Try { TryResponse response[] attempt(TryObject ...
2
votes
2answers
108 views

Is retaining intermediate objects as member fields a good idea in this case?

I'm currently writing a series of classes in java that are meant to translate a regular expression (written with the formal definition, not language-specific shortcuts) into a deterministic finite ...
0
votes
2answers
67 views

Can I use a package visible constructor for creation?

I need a class where this can be done: // user program elder_tales.Player p = elder_tales.generate_player(); elder_tales.level_up_player( p ); but not: // user program elder_tales.Player p = new ...
0
votes
0answers
51 views

delegate classes for UI events

When designing a delegate to represent the state of a UI (java swing) what is cleaner: to manipulate the delegate directly from the custom event handlers defined in the UI code, or to register the ...
3
votes
2answers
330 views

Object-Oriented design and proper Java architecture for my program

This is the very first time that I think I want to create a program which really uses OOP principles and I want to do it in the most effective and efficient way. First of all we are given this ...
2
votes
3answers
140 views

Refactor an old model of a LastUser Modification on every Object?

I have a software requirement, that needs to store the user that made the last modification to another object, for every object (assume that all objects are already mapped and into a BD). So we have ...
5
votes
2answers
1k views

Open Close Principle (OCP) vs Dependency Inversion Principle (DIP)

I was trying to understand the difference between Open Closed Principle (OCP) and Dependency Inversion Princible (DIP). Based on research I've made on the internet so far, I came to the conclusion ...
1
vote
3answers
263 views

Service method, bean as an argument and mandatory attributes

There is a service: createUser(User user) where you can create a new user, with so many attributes (name, address lines...). Now, some user attributes are mandatory. Other attributes are not ...
0
votes
1answer
239 views

Flexible / Dynamic object creation or Alternative to list of lists [closed]

I have a xlsx file, that has some tabs with different data. I want to be able to save each row of a tab in a list. The first thing that comes to mind is a list of lists, but I was wondering if there ...
7
votes
4answers
323 views

Is throwing an error in unpredictable subclass-specific circumstances a violation of LSP?

Let's say I wanted to create a Java List<String> (see spec) implementation that uses a complex subsystem, such as a database or file system, for its store so that it acts as a persistent ...
0
votes
3answers
278 views

When should method overloads be refactored?

When should code that looks like: DoThing(string foo, string bar); DoThing(string foo, string bar, int baz, bool qux); ... DoThing(string foo, string bar, int baz, bool qux, string more, string ...
0
votes
4answers
451 views

Does it make sense to generate java classes from class diagram?

As we do design & analysis before development, wouldn't be convenient to be able to generate Java classes from a class diagram? This would promote more exhaustive design and better codes, right? ...
1
vote
1answer
166 views

When should one use composition instead of re-writing the functionality?

Say, I have a class A which has methods m1,m2,m3,m4,m5.... m100. I am making another simpler class B and I require only m2,m3 and m5 in B. Should I be ideally using compositions and put a reference ...
2
votes
2answers
606 views

OOP Objects, nested objects, and DAO's

Here's something I keep struggling to figure out the best solution to. I've had this problem while working with PHP and Java so it's a fundamental understanding of OOP issue. Examples are in PHP. ...
1
vote
4answers
486 views

How to get Object Oriented Programming Concepts? [closed]

What is the best way or best resources or tutorials to learn Object Oriented Programming? For instance, when I begin a program with Java and all my code goes into just one class and I can't estimate ...
0
votes
3answers
271 views

Liskov substitution principle when implementing two unrelated interfaces

Suppose I have two unrelated interfaces with the same method: interface Table { /** * @param width (0 < width <= 100) */ void setWidth(int width); } interface Square { ...
11
votes
3answers
1k views

How to create better OO code in a relational database driven application where the database is poorly designed

I am writing a Java web application that consists mainly of a bunch of similar pages in which every page has several tables and a filter that applies to those tables. The data on these tables comes ...
0
votes
1answer
117 views

Creating Set Subclasses or Allowing Outside Configuration

I have a TriggerCaller and a TriggerAction class. The Caller "calls" the do() method on the action, which is set with the TriggerCallers setAction() method. The rest of the program should deal with ...
0
votes
3answers
657 views

Have Superclass Contain List of Subclass?

For the GUI of a program, I want it to list several items, all of which are, from a programming side, just subclasses. They can add one of these items to a list. I don't want to hard-code which ...
9
votes
4answers
917 views

Is the List interface a leaky abstraction?

If I have a variable containing a List it could contain objects of a lot of different types e.g. ArrayList or LinkedList. The difference between a LinkedList and an ArrayList is pretty big. The big O ...
2
votes
2answers
2k views

When to use inheritance or composition/aggregation?

In general, how do I decide whether to use make a class a super class, or to make it a private data member of another class? For example, given two classes, how does one decide whether to do this: ...
0
votes
3answers
122 views

Should a complex unifying class be doing computation?

I have a large application in Java filled with independent classes which are unified in a PlayerCharacter class. The class is intended to hold a character's data for a game called the Burning Wheel, ...
17
votes
3answers
2k views

Using public final rather than private getters

I see most immutable POJOs written like this: public class MyObject { private final String foo; private final int bar; public MyObject(String foo, int bar) { this.foo = foo; ...
7
votes
7answers
3k views

Should I create interfaces for data transfer objects?

Is it a good idea or a bad idea to create an interface for data transfer objects? Presuming that the object is usually mutable. Though my example is in Java, it should be applicable to any other ...
5
votes
2answers
1k views

Visitor stability vs instanceof flexibility

I am working on a GUI application which generates a configuration file. I have a class hierarchy for the configuration model and I use an object tree of that hierarchy in several different contexts. ...
2
votes
0answers
388 views

Why does Java's Collections.unmodifiableList return a List interface instead of an UnmodifiableList interface? [duplicate]

Possible Duplicate: Why were Java collections implemented with “optional methods” in the interface? I was looking at the javadoc for Collections and I noticed the ...
9
votes
4answers
635 views

Good implementation strategies for encapsulating shared data in a software pipeline

I'm working on re-factoring certain aspects of an existing web service. The way the service APIs are implemented is by having a kind of "processing pipeline", where there are tasks that are performed ...
4
votes
6answers
3k views

What are abstract classes and abstract methods?

I got several explanations but so far I'm not able to understand that what are the abstract classes and methods in Java. Some said it has to do something with the security of the program, other said ...
1
vote
1answer
1k views

Use decorator and factory together to extend objects?

I'm new to OOP and design pattern. I've a simple app that handles the generation of Tables, Columns (that belong to Table), Rows (that belong to Table and have Columns) and Values (that belong to ...
5
votes
1answer
891 views

Why doesn't Java's BigInteger class have a constructor capable of taking a numeric literal? [closed]

Why doesn't Java's BigInteger class have a constructor capable of taking a numeric literal? Every single time I use BigIntegers, and many times I merely think about them, I wonder this. What reason ...
1
vote
3answers
349 views

Any tips/tricks/resources on actually TEACHING a class on OOP? [closed]

I may slowly be getting into teaching an Object-Orientated Programming class at my school in a year or two. I just graduated and work at my school as an Application Programmer. I'd first start off as ...