1
vote
2answers
111 views

How to let the outside world decorate my private field?

Imagine a simple Controller (as in process control) interface. I have some concrete classes, say PIDController, that implement it. I also have some decorator classes that extend these classes ...
0
votes
3answers
132 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
162 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
3answers
166 views

Drawback of using static method [duplicate]

For methods that never access instance variable or static variable and they act just like a function (name-spaced) and they are deterministic base on only the input arguments , I want to ask, are ...
0
votes
1answer
113 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
1answer
166 views

I'm always reimplementing observer/subject code in Java. Is there a better option?

I'm always writing observer/subject interfaces in a particular Java project, e.g.: /** * Registers the receiver to the dispatcher. * When data arrives that the receiver can process, * it will be ...
1
vote
3answers
142 views

Protected variable & protected method in the era of TDD [closed]

I understand protected method is good for unit testing since you can easily mock by the class by overriding the protected method for the sake of testing. However, protected variable is just a global ...
0
votes
1answer
233 views

Implementation of strategy design pattern

Here is my code: public class StrategyDemo { public static void main(String[] args) { Phone ipPhone = new IPPhone("1234", "ProviderA"); Phone tdmPhone = new ...
0
votes
3answers
255 views

Does the pattern of passing in one object instead of many parameters to a constructor have a name?

If you have a constructor that takes a lot of parameters, like this: public OrgUnitsHalRepresentation(List<OrgUnitSummaryHalRepresentation> orgUnitSummaryHalRepresentationList, int count, ...
1
vote
0answers
90 views

Which patterns/architecture to apply for “Import Data, Process Data, Export Result”

I was wondering which architecture/patterns to choose for the following problem divided into three steps: Import TestScript Description from File (e.g. .xls, .txt) Process Described TestScript ...
0
votes
1answer
126 views

What is design pattern/paradigm for ASP.NET web-apps? [closed]

I don't actually know if my question is correct, but working on a webapp porting from ASP.NET world to Java + Spring platform I came up with this question in mind. Using Spring MVC, the new version ...
1
vote
3answers
314 views

Passing data between hundreds of objects in java [closed]

Currently, I'm working with a group on building a model. This model simulates interactions between many "agents" in a region. Agents can be any entity such as a city, a farmer, a business etc. Each ...
2
votes
1answer
160 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 ...
4
votes
3answers
82 views

Returning results of method on batch list?

The title is a bit vague so I'll try to elaborate. I have a function makeFoo(int bar) -> returns Foo or throws Exception. I also have a batch version of this makeFoos(int[] bars) -> ...
1
vote
1answer
131 views

How to design extension mechanism for java app

I have an application where I have a set of core features. The application itself HAS to work in core only mode. I would also want to make the application extensible such that, when certain ...
0
votes
0answers
8 views

Select design pattern - user stage [duplicate]

I'm struggling to point a finger into the right design pattern. I have a web site which user can register and interact with the system. I want to add the following abilities to a user: Each user ...
0
votes
2answers
156 views

DTO - service layer - statelessness best practices interfering with each other

I am designing a REST API coupled with a service layer that takes DTOs as input and produces them as output. This works fine for most service calls where the DTO is used to access an underlying ...
0
votes
1answer
76 views

Implement RPC via SIP

Look at the following use case. I have a client (Java) application, which wants to get/set the state of another, remote application (C). The communication between them is done via SIP, which is run ...
3
votes
2answers
244 views

Is the Java Integer cache a realization of the object pool pattern?

One of the best-known examples of a full-fledged object pool is the JDBC connection pool. Main reasons: objects in the pool are expensive to create and relate with external resources each object in ...
2
votes
1answer
157 views

Working with a large, messy object [duplicate]

I have been handed a very cluttered, "One Ring" object (one object to rule them all). The OR class has 40 fields. These fields map to 16 different objects (the OR has all the fields from the 16 ...
-2
votes
4answers
238 views

What is the name of this design pattern? [closed]

I have been using this "design pattern" (may or may not be an "official" design pattern) for a while and I wanted to know if it had a name (so that I could name my classes after it). Example in PHP ...
0
votes
0answers
95 views

Android From Local DB (DAO) to Server sync (JSON) - Design issue

I sync data between my local DB and a Server. I'm looking for the cleanest way to modelise all of this. I have a com.something.db package That contains a Data Helper and couple of DAO classes that ...
7
votes
2answers
512 views

Can someone explain in simple terms what is the disruptor pattern?

I would like if you could explain to me in a simple way how does the disruptor patter work. This concept has been elusive to me as of know. Perhaps with your help I could comprehend it.
-1
votes
2answers
185 views

Help with MVC design pattern? [closed]

I am trying to build a java program for user login but I am not sure if my MVC design is accurate. I have the following classes: LoginControl - servlet LoginBean - data holder java class with ...
5
votes
3answers
209 views

How to refactor my design, if it seems to require multiple inheritance?

Recently I made a question about Java classes implementing methods from two sources (kinda like multiple inheritance). However, it was pointed out that this sort of need may be a sign of a design ...
19
votes
4answers
3k views

Builder Pattern: When to fail?

When implementing the Builder Pattern, I often find myself confused with when to let building fail and I even manage to take different stands on the matter every few days. First some explanation: ...
0
votes
2answers
144 views

Is using interfaces on internal code a good idea? [duplicate]

I'm working on a set of automated tests that we use internally at work. Lately, we've been designing classes that implement interfaces in addition to inheritance. As I understand it, interfaces in ...
2
votes
1answer
98 views

What's the right OO way to create a counter/inventory class that works for both differentiated and undifferentiated countables?

You are writing a videogame about trading beans. Red beans, black beans, pinto beans, you name it. As everybody knows all beans are the same. You write the "Inventory" class for a trader in that ...
18
votes
5answers
3k views

How would another popular language avoid having to use the factory pattern while managing similar complexity as in Java/Java EE?

Factory pattern (or at least the use of FactoryFactory..) is the butt of many jokes, like here. Apart from having verbose and "creative" names like ...
1
vote
2answers
145 views

Java Method Returns Unbounded Type

I was reading this article, https://weblogs.java.net/blog/emcmanus/archive/2010/10/25/using-builder-pattern-subclasses, about subclassing a builder class. I understood the article but there was one ...
-1
votes
1answer
186 views

How to create a some kind of value for sentences? [closed]

I want to identify most matching sentence using some pattern. That means by using java algorithm I want to create identical value for each sentences.Each sentence when entering to that algorithm can ...
4
votes
2answers
250 views

How to decouple simple factory and default implementation?

I have a simple factory class (FileResources) with static factory methods providing a default implementation (DefaultFileResource). public final class FileResources { private FileResources() {} ...
22
votes
2answers
3k views

How to improve upon Bloch's Builder Pattern, to make it more appropriate for use in classes that may be extended and sub-extended many times over?

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 ...
1
vote
1answer
250 views

Android Data persistence question

I have an android app in which users have sets of items, and each item has about 10 properties. What I do at the moment: items are stored in the server database when the user logs in, I get all the ...
0
votes
1answer
226 views

Email Content creation | Proper design

Working on an E commerce application where we need to send so many email to customer like Registration email Forget Password Order placed There are many other emails that can be sent, I already ...
0
votes
2answers
148 views

Best way to display domain object summary information efficiently and in an OO way from a large inheritance tree?

I've provided only simplified code as it's more of an abstract design question. So I have many, many nested business/domain event objects, e.g. public class Event { //bunch of properties and ...
0
votes
1answer
136 views

Using a variable in a Global context in webapps

In a webapp, I have a scenario where I need some kind of global context (Static like) for few variables, for the current thread only. If there are 3 different concurrent users, then I expect three ...
2
votes
2answers
327 views

Best practice with respect to anonymous classes in UI applications

When working with user interface based Java programs, one way of attaching behaviour to a certain actions (e.g. to a button click) is through the use of anonymous classes. In the example below, the ...
3
votes
3answers
425 views

Why should a builder be an inner class instead in it's 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 static a static type language we ...
4
votes
1answer
333 views

State pattern vs Inheritance

In the following image for the State Pattern from Applying Domain-Driven Design and Patterns: With Examples in C# and .NET I'm trying to persist the SalesOrder entity into the database. Normally I ...
1
vote
1answer
222 views

Decorator Pattern in Head First Design Patterns

I'm trying to teach myself some design patterns using a book that I was recommended, Head First Design Patterns. I came to the chapter on the Decorator Pattern, and although I understand the purpose ...
1
vote
2answers
278 views

If every instance of a type is to be random, how should the Random generator object be stored?

It seems to me that this is often encountered in practice and I was wondering if there is a design pattern for the following: Suppose I have a class that represents a card: public class Hand { ...
3
votes
3answers
1k views

Which design pattern is more suitable for logging?

I should log some events in a program but as far as I know it would be better to keep the logging code outside the program because it is not about the real functionality of the program. So may you ...
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 ...
0
votes
2answers
218 views

Best place for a factory interface

What's the best place for a factory interface to create an instance of another interface? OptionA: a separate class public interface InterAFactory { InterA createInterA(); } public interface ...
0
votes
1answer
238 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 ...
2
votes
3answers
290 views

Which one of these designs is preferred? [duplicate]

In the case of an application with a single simple responsibility (eg, a simple replacement for grep or wc), which of these designs is preferred and why? I find that they are all testable and they all ...
13
votes
3answers
4k views

Static factory vs factory as a singleton

In some of my code, I have a static factory similar to this: public class SomeFactory { // Static class private SomeFactory() {...} public static Foo createFoo() {...} public ...
2
votes
3answers
471 views

Layering Design Pattern in Java clean code style

As a Java developer, I am developing trying to use the clean code rules. But in my team we are facing a concrete problem: We have a business layer offering a service called "createObject", this ...
1
vote
1answer
200 views

Is there a name for the Builder Pattern where the Builder is implemented via interfaces so certain parameters are required?

So we implemented the builder pattern for most of our domain to help in understandability of what actually being passed to a constructor, and for the normal advantages that a builder gives. The one ...