16
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
votes
0answers
57 views

Java: Singleton Event Driven Design [closed]

I have a singleton class ( I make this as immutable ). This class is present in the base module. It has a static method getInstance() which will initialize a new object based on the data stored in a ...
1
vote
2answers
133 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
151 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
212 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() {} ...
18
votes
2answers
2k 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
191 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
133 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
124 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
106 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
205 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
276 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 ...
3
votes
1answer
231 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
194 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
3answers
258 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
635 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
487 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
200 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
229 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
288 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 ...
12
votes
3answers
2k 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
430 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
186 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 ...
2
votes
7answers
477 views

Is there a pattern to restrict which classes can update another class?

Say I have a class ImportantInfo with a public writable property Data. Many classes will read this property but only a few will ever set it. Basically, if you want to update Data you should really ...
0
votes
1answer
83 views

How are the forwarding of requests normally managed in the Chain of Responsibilty pattern? [closed]

I was just experimenting with the Chain of responsibility pattern, implementing my own version. I'm currently reading Design Patterns, but I'm not really sure whether DP tells to stop your ...
1
vote
2answers
287 views

Loadbalancing and failover in code

I have HTTPS based webservices (not REST, rather old code). I am generating Java client stubs using Axis & using that to call the webservices. There are around 20 different APIs on the webservice. ...
2
votes
1answer
261 views

Optimized Special Character Escaper vs Matcher/Pattern

I need to escape special characters which are sent to apache lucent. Since the code will run on a production server I want the code to be the fastest possible. I've seen multiple ways to do it: ...
0
votes
0answers
77 views

Recaching calculations

I'm working on a webapp which has an existing framework to cache values from the database. I have a requirement which needs multiple values from the database and the values have to be ...
1
vote
1answer
112 views

how to model a connection to a resource, with rudimentary event processing

For my simple MUD client I'm using Apache Telnet (no, not ssh). A mud client is a strange beast: Generally, a MUD client is a very basic telnet client that lacks VT100 terminal emulation and the ...
3
votes
1answer
207 views

Mutual observer pattern in Java

I want to improve my multi-threading and design pattern skills. As such I'm designing an Instant Messaging server. I'm writing the Server first. My plan so far is to have Client "Proxy" Classes to ...
4
votes
2answers
695 views

How does MVC work with the principle “Tell, Don't ask”?

Procedural code gets information then makes decisions. Object-oriented code tells objects to do things. — Alec Sharp So, when a view wants to display some information that is suppose to be ...
13
votes
9answers
3k views

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

Law of Demeter issues with complex class design

I've posted questions pertaining to this issue before, but they've all tackled different aspects of the problem (Just so you know that I'm not reposting the same question to get more answers). So, in ...
2
votes
3answers
376 views

Parallel Class/Interface Hierarchy with the Facade Design Pattern?

About a third of my code is wrapped inside a Facade class. Note that this isn't a "God" class, but actually represents a single thing (called a Line). Naturally, it delegates responsibilities to the ...
-3
votes
1answer
186 views

Best Object Oriented way of parsing a model with several fields(>50) and with null checks

I have a JSON-based data which contains many fields from a particular model. Any value from the list of fields can be null. I am trying to find the best object oriented way of parsing it and also it ...
3
votes
2answers
267 views

Can classes violate Single Responsibility if they delegate internal tasks?

I have two classes Output and Timeline, neither of which violate SR, but the two of them are linked together. So what I'd like to do is have a class called Elco (there's a reason behind the name) that ...
1
vote
4answers
462 views

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 ...
2
votes
4answers
146 views

Subclassing to change default settings?

I have a class called Timeline. I want to allow several defaults in my code, such as a Timeline with a Start event (The details are not needed. All that matters is that I have a class, and I want to ...
3
votes
4answers
358 views

Law of Demeter causing subclassing indecision and conflict with Single Responsibility

This is my situation: I have a class called CueList, which is basically a wrapper around ArrayList. I have another class called TimeTicker that alerts all the Tickable (interface) in its list that a ...
0
votes
2answers
287 views

Factory-Class versus Static Class

I've got a little problem in choosing the best design. I have some (5 at the moment) image processing operations in my coe (Java). Every processing step independent from the other ones and consoists ...
0
votes
2answers
789 views

Implementing MVC pattern in SWT application

I am developing an SWT application (it's basically an Eclipse plugin, so I need to use SWT). Currently my design is as follows: Model: In model, I have POJOs which represents the actual fields in ...
4
votes
2answers
342 views

Hide or Show singleton?

Singleton is a common pattern implemented in both native libraries of .NET and Java. You will see it as such: C#: MyClass.Instance Java: MyClass.getInstance() The question is: when writing APIs, ...
0
votes
2answers
133 views

Memento with optional state?

EDIT: As pointed out by Steve Evers and pdr, I am not correctly implementing the Memento pattern, my design is actually State pattern. Menu Program I built a console-based menu program with multiple ...
3
votes
1answer
76 views

Should I write a wrapper within a manager object?

I have three classes that work together to do one function (from the perspective of the rest of my program). There is a little bit of set up between them, so, to make it easier for the rest of my ...
4
votes
2answers
212 views

How to delete an object when other things reference it (and not making the code full of inter-dependencies)

The situation: In my program, there are a list of cues. To call a cue at a certain time, there are objects called Triggers. Cues have many public methods that allow them, among other things, to be ...
2
votes
3answers
232 views

MVC seems to create dependencies that just “don't feel right”

I might be misunderstanding MVC, so forgive me if that is the case. This is my program structure (Java/Swing): I have a JTable (View) that is pointed to by a custom linked list (Model). When the user ...
1
vote
1answer
241 views

Creating a System Sequence Diagram from an [extended] use case

As I have been taught - one controller = one use case. But I have: OutsiderController SupplierController (which extends OutsiderController) SubContractorController (which also extentds ...
2
votes
1answer
250 views

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 ...
0
votes
1answer
172 views

Where should I put my method

I am writing a Java program using the MVC design pattern. I have classes Item and Supplier. In the database they are connected through a item_supplier table. I'm writing a method which will give me ...
0
votes
1answer
63 views

How to record/store edits?

In many programs and web apps (stack exchange included) the program is able to backtrack what edits where made to the piece. My issue is similar: I want to be able to store a "timeline" of edits, ...