Skip to main content

All Questions

35votes
6answers
9kviews

Should I extract specific functionality into a function and why?

I have a large method which does 3 tasks, each of them can be extracted into a separate function. If I'll make an additional functions for each of that tasks, will it make my code better or worse and ...
dhblah's user avatar
  • 1,381
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 ...
Gurtz's user avatar
152votes
6answers
118kviews

What is the point of having every service class have an interface? [duplicate]

At the company I work at, every service class has a corresponding interface. Is this necessary? Notes: Most of these interfaces are only used by a single class We are not creating any sort of ...
Bob Roberts's user avatar
31votes
5answers
36kviews

What is the difference between all-static-methods and applying a singleton pattern? [duplicate]

I am making a database to store information about the users of my website (I am using stuts2 and hence Java EE technology). For the database I'll be making a DBManager. Should I apply singleton ...
shahensha's user avatar
179votes
6answers
303kviews

What is the point of using DTO (Data Transfer Objects)?

What is the point of using DTO and is it an out dated concept? I use POJOs in the view layer to transfer and persist data. Can these POJOs be considered as an alternative to DTOs?
Vinoth Kumar C M's user avatar
15votes
5answers
95kviews

A way to return multiple return values from a method: put method inside class representing return value. Is it a good design?

I need to return 2 values from a method. My approach is as follows: create an inner class with 2 fields that will be used to keep those 2 values put the method inside that class instantiate the class ...
dhblah's user avatar
  • 1,381
7votes
3answers
5kviews

How to create a manager class without global variables nor singletons?

I would like to implement some kind of manager class in my application. It will be in charge of loading textures, processing them, distributing them etc... At first, I wanted to make a global ...
Saturn's user avatar
  • 3,937
11votes
1answer
7kviews

Template pattern with varying input type in overridden method

I am trying to use template pattern to define a generic algorithm in java. But the method that needs to be overridden, takes an object as input. This object will vary depending on the concrete ...
Rishi's user avatar
4votes
1answer
2kviews

Do I need JUnit tests for the controller layer on a MVC when I have a database layer

I have a MVC which has this structure: ui controller db model Basically the controller doesn't really do much more than connection ui with db layer. Do I need to provide JUnit tests for the ...
Nikola's user avatar
3votes
5answers
2kviews

Explanation of the definition of interface inheritance as described in GoF book

I am reading the first chapter of the Gof book. Section 1.6 discusses about class vs interface inheritance: Class versus Interface Inheritance It's important to understand the difference between an ...
Geek's user avatar
  • 5,217
2votes
4answers
345views

Builder with non-defaultable required args

Suppose a class needs multiple properties of the same type. I don't want a big constructor where the user can mess up the order of args (remember, they are of the same type, no compile-time errors) ...
Sergey Zolotarev's user avatar
0votes
3answers
779views

Is this 'implementation' of a builder pattern good design

public class MyButton{ public MyButton(){} public MyButton setIcon(Icon icon){return this;} public MyButton setText(String text){return this;} } And used like: MyButton testButton = new ...
Rulasmur's user avatar
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 ...
aliteralmind's user avatar
30votes
2answers
31kviews

Why should a builder be an inner class instead of in its own class file?

Many Builder Pattern examples make the Builder an inner class of the object it builds. This makes some sense since it indicates what the Builder builds. However, in a statically typed language we ...
Nathanial's user avatar
14votes
9answers
22kviews

Are too many if-else statements for validation bad? [duplicate]

From the book Professional Enterprise .Net, which has 5 star rating on Amazon that I am doubting after having a read through. Here is a Borrower class (In C# but it's pretty basic; anyone can ...
iAteABug_And_iLiked_it's user avatar

153050per page
close