All Questions
117 questions
39votes
6answers
31kviews
Why avoid Java Inheritance "Extends"
Jame Gosling said “You should avoid implementation inheritance whenever possible.” and instead, use interface inheritance. But why? How can we avoid inheriting the structure of an object using the ...
37votes
2answers
26kviews
How to improve upon Bloch's Builder Pattern, to make it more appropriate for use in highly-extendable classes
I have been greatly influenced by Joshua Bloch's Effective Java book (2nd edition), probably more so than with any programming book I've read. In particular, his Builder Pattern (item 2) has had the ...
27votes
4answers
10kviews
Legitimate "real work" in a constructor?
I am working on a design, but keep hitting a roadblock. I have a particular class (ModelDef) that is essentially the owner of a complex node tree built by parsing an XML schema (think DOM). I want to ...
22votes
11answers
2kviews
Choose code design effort or laziness in Bank world
I've worked for two years in a great Investment Bank. I made some technical projects with the desire of creating code the most optimized, respecting the adapted good design patterns, SOLID principle, ...
18votes
8answers
4kviews
Refactoring a long method which is based on large number of switch cases [duplicate]
We are using Java as a backend development language. One year back, we wrote a method which uses switch cases based on Enums values. Since we are continuously adding enum members and according adding ...
18votes
4answers
16kviews
Java - Is it a bad idea to have fully static classes?
I'm working on a larger solo project and right now, and I have several classes in which I do not see any reason to create an instance of. My dice class right now, for example, stores all of its data ...
16votes
9answers
17kviews
How to split large, tightly coupled classes?
I have some huge classes of more than 2k lines of code (and growing) that I would like to refactor if possible, to have some more light and clean design. The reason it is so big is mainly because ...
16votes
3answers
25kviews
Should a DAO be singleton or not?
I am developing a RESTful API and I think it is convenient to use DAOs for my resources because although I plan on just using memory to store them, I don't want to close a door to whoever is using my ...
12votes
2answers
3kviews
Separating Business logic from DB-logic with transactions
We have three layers in our application. Service layer to provide an external API. BO layer for our business logic, and a DAO layer for our database connection. Let's say every time we update a File,...
9votes
4answers
5kviews
How to force "program to an interface" without using a java Interface in java 1.6
In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: use code to keep clients from being able to tell that a class is not a java interface. If we ...
8votes
3answers
3kviews
Refactoring an existing abstract class and its parameters
I have an abstract class A which declares an abstract method doStuff. Currently there are many classes that inherit from A and implement doStuff. The class' instances are initialized at run-time ...
7votes
5answers
3kviews
Design pattern for 2 methods one has 70% arguments of other one
I am trying to do a design for notification part in the system I have 2 parts inApp notification and email notification so I used strategy pattern where I have interface NotificationSender with one ...
7votes
4answers
1kviews
Applying DRY to an inheritance hierarchy
I'm working on refactoring a legacy application where I implemented the State pattern successfully as shown in the following diagram: As you see there is a common behavior between the 3 states, so I ...
7votes
3answers
384views
When module calling gets ugly
Has this ever happened to you? You've got a suite of well designed, single-responsibility modules, covered by unit tests. In any higher-level function you code, you are (95% of the code) simply ...
7votes
2answers
6kviews
Is the builder pattern appropriate to use to update Objects in a Service layer?
Currently, in our service layer, we pass an id as well as a new updated value, something akin to updatePersonName(Person person, Name name) which, in turn, calls the corresponding repository ...