Tag Info

New answers tagged

3

On the one hand I can argue this does not violate SRP, because the whole use is database communication. You could also say you have a single class in your application, because the whole class does processing of data. It doesn't work like this. If your class has: a mix of different abstraction levels; a mix of things that can be described as separated ...


3

Yes, I think you are violating the SRP. Not because you kept all of your database code in one class, but because you have database code for completely different entities (users, products, events, friends) all in one class. At the very least, separate your code into classes by the entity it's most closely related to. If you're looking for design patterns, you ...


0

I understand your doubts, because such service-mixins don't look natural for me either. But why? Strictly speaking, even in complete SOA architecture service composition is not forbidden. But your case is different. Your services are not independent units located in own processes with independent transaction management. Your services are just level in your ...


0

A Save() method for a complex object would go into your Repository pattern interface. No, you don't necessarily need to use a different pattern. A Repository should ideally abstract away all underlying storage (i.e. DB, memory collection, XML file etc) implementation detail from the object model that it works with. So if you are creating a complex object ...


1

Most algorithms will come up with a randomly generated map purely based on a seed. It would never evaluate the map, and therefore not guarantee a nice user experience. Since you have mentioned that you would like to build a "state of the art" map generator, the first thing that comes to my mind is genetic algorithms. Such an algorithm would create many ...


4

Users do not like change. Even when the change is objectively superior from an UX perspective, the human resistance to change habits will result in them finding it subjectively worse. So when you already have a userbase you are developing the new application for, it is not a bad idea at all to follow the UI conventions they are used to instead of following ...


0

If the Key object is already unique itself, not by equals() but by instance, and in case the key would actually never be null (and the code could be changed / the null key case could be removed), you could change the get() function to: static C get(Key key) { synchronized (key) { C c = cs.get(key); if (c==null) { c = new ...


1

If the only problem with initializing multiple copies of a single object value is the time/memory it takes, you may want to consider switching to a ConcurrentHashMap and using the computeIfAbsent method to initialize values. This has the side effect that two copies of a single value may be initialized, however only one will be retained (the second will be ...


1

This is a variation of the singleton pattern, called Multiton. You will have to manage the global state introduced with the HashMap. This can lead to diffucult unit testing. The implementation of the synchronized method looks the same, as shown in the Wikipedia article. But if you can restructure your use case, so that you can avoid the synchronizing of ...


1

In his book Effective Java, Josuha Bloch mentions this pattern as a good practice for this sort of scenario (Item 1: Consider static factory methods instead of constructors). Some common alternative names for the method that here is called C.getare the following C.getInstance, C.valueOf, C.of.


3

What you describe are known as JavaScript Promises, in general programming parlance they are called Continuations. C# supports them through the Task Parallel Library and Async/Await keywords. Here's how it works, I want to call an operation asynchronously. If the operation is already declared Async it's simple: Add async to your function that is calling ...


2

The abstract Controller class can't create the right <concrete class>Domain classes, because it doesn't know which concrete class it belongs to and which Domain and View classes it should be associated with. What you can do is pass in the Domain and View classes from the derived class's constructor. abstract class Controller { private $domain; ...


0

Please take a look at the following thread. Groups is usually the simplest way to go. Note, you don't necessary have to have 'Group' object and link it to your roles/users, simpler approach is tagging. Having specific set of tags on the objects itself identifies the set of groups it belongs to - hence the permissions. Fox [tags: auto, fruit] Auto [tags: ...


0

I think solution 2 is the better solution. You want to avoid treating connection commands as special cases. That would add complexity to your script engine and/or script language. Your commands should receive a general purpose execution context (or script state). Some psuedo-code could be: interface ICommand { void Execute(IScriptContext context); } ...


1

As others have answered, DAO and DTO reflect the role of the Object whether you want to use it in a persistence layer or to transfer informations in a call. A value Object should be immutable. Since your code is in Java (and the terminology is quite Java Oriented), the term that comes to my mind is JavaBean but your class should implement Serializable. I ...


0

In the .NET world, your class qualifies as a plain old CLR object (POCO). In the Java world, you have plain old Java objects (POJOs).


2

I would call them structs. An old school name for old school design. DAOs contain persistence-related functionality. That's not a DAO. That could be a poorly implemented value object. Value objects should generally be immutable and they should have proper constructors. (However, a configuration could very well be an example of a value-like object that ...


3

There isn't, so far as I'm aware, a general name for production code created specifically for the purpose of unit tests. With the notable exception of friend-assemblies (for unit-testing internal units) such code would normally be a smell indicating that something's up with the shape of your class' public signature. This particular example, however, does ...


5

I certainly wouldn't call it a value object because that conflicts with the idea in domain-driven-design. Going from wikipedia: In computer science, a value object is a small object that represents a simple entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same ...


0

I've heard and used both Data Access Object and Data Transfer Object, though I usually just call them Data Models (Objects) because it implies a container and doesn't imply what you are actually going to be doing with it.


9

A DAO class usually has the CRUD operations like save, update, and delete. Whereas the DTO is just an object that holds data. So there is actually a difference between those two. The term then depends on what the object does. A VO and DTO used to be synonyms: early Java EE literature used the term value object to describe a DTO, but it changed it in a ...


-2

Assuming you do not accept the argument (which I believe is well worth considering) that the fact that the separated ISomething is required for testing tells you that it may also be required kn future to make your class more flexible, one possible fix would be to mark the constructor as deprecated and disable deprecation warnings for the line of the test ...


0

Two possible cases when you may want to change your production code for testing purposes: If you have complex functionality in the class And your open interface does several things combined so you can not test each of the functionality separately this means when a combined test fails you still don't know which part is broken YES, it is good to separate ...


26

For methods of a class which are solely for testing purposes, I have seen the name maintenance hatch in the past. And similar to real maintenance hatches in physical machines, those methods sometimes have their purpose. For example, if you are going to make some legacy code testable when it has grown too big after some years of evolving, maintenance hatches ...


12

It's called "production code included for the sole purpose of facilitating testing." If you're using it a lot, I'd say it's an anti-pattern. The way you mitigate it is to write your classes using dependencies which conform to an Interface and are supplied using Dependency Injection, and then use stubs and mocks to isolate the class for testing. But the ...


7

One term which has been used for this recently is test induced design damage. Telastyn is correct that your code snippet isn't actually a very good example of this concept, though. A more common occurence is that a test wants to set up a class to be in a particular state during its "arrange" phase, but due to encapsulation, doesn't have any way to do that ...


16

It was added purely to test this class, and will make its way into production code. This is shortsighted... Having a constructor to pass in dependencies isn't done just to test the class. It's done to make your class flexible. The parameterless constructor that has a hard dependency on a concrete Something is more of the anti-pattern due to the tight ...


0

You could use an EventBus. When using a bus system, components in your application can register for events that are fired by other components. This way a monster could fire a MovedEvent ore something that contains the necessary data. There are several implementations in several languages. In java, commonly used one is part of guava: ...


1

In the example you give (mission controller turns monsters blue), you wouldn't need communication between the controller and the monsters. Instead the monsters could look up the "monster color" in a palette (or color table). The mission controller just sets a different value for "monster color" in the palette when the mission changes. Or switch the entire ...


4

As with all program design, if you have two things that need not know about one another (A and B) then the proper design is to have some mediator C that lives above and knows about both: C / \ A B The mediator can then glue the two together via a generic decoupling mechanism (events, messages, delegates, just passing one into the other, etc). For ...


1

There's a risk that the second approach leads to a Fat Controller, which is often considered an antipattern. It's effectively a violation of "clean architecture" (as by Uncle Bob Martin) since your controller is now not only a "delivery mechanism" but also deals with applicative transactions/use cases, orchestrating calls to the repositories and services and ...


0

Imagine a Chinese person who doesn't know English who's trying to read your configuration file. Alternatively, imagine the configuration file is in Arabic (and that you don't known Arabic). Now ask yourself, is this really human readable? Even if the reader does know English, they've still got no idea if "logger.datarate = 100" means 100 characters per ...


1

I say what you have (properties file) is already the best human readable configuration format. :) Here are my arguments: Properties file is just key/value pair. Easily readable by human. Terse syntax, not like xml. Easily nest-able, with '.', like in your example. Flat structure allows easy diffing in a source controlled environment. That last point is ...


1

By the general description given, it sounds as though the concrete types WordBank and WordSorter (might be better called WordFilter) should be separate types both implement from a common interface IWordSource, and/or inherit from a common abstract base class WordSourceBase which does so, rather than having either concrete type inherit from the other (setting ...


4

As the null-implementation is supposed to be a drop-in replacement for the full-functional implementation, the null-implementation should fully adhere to the interface that it implements. If the WifiComponent interface specifies that connect() throws an exception if it gets invoked with an unsupported WifiEncryptionType, then that is exactly what your ...


3

Should we use another way for sharing data between these three classes? No, that is not the point of what Fowler is talking about. The usage of a DTO is probably fine (Fowler himself recommends it, especially in a remote scenario). The point is that during refactoring, such a DTO might become a better place for operations which work exclusively on the ...


1

As I see it, the ORM doesn't create the side effects, your code does. If you ask an ORM to save an entity, it does so, without performing additional operations, or should there be a database trigger of some sort, in my personal opinion you should remove it in favor of having more control in your program. As such, don't worry about saving your entity ...


-2

Patterns are common solutions to common problems. We are always following some patterns, the patterns by GoF address the most recurring ones. That, to have a shared understanding and shared approach known to software engineers. That said, my answer is no, but yes you are always following some pattern of your own. As the GoF rightly puts it- One ...


1

The first solution you have proposed is an excellent solution, as it namespaces your code properly and means that your code is in the correct structure should you want to shared your code through a package manager (like packagist) later on. If, at some point, you intend to share you code to other developers via something like packagist, you would do the ...


0

You asked several questions, some of which have good answers already. A few have not yet had their answers: What I want to know is, why did we make such a transition (from the emphasis of server-side programming to client-side, ... all of these seem to have occurred simultaneously) and what problems did this transition/shift solve? Robert Harvey gave ...


0

This Client vs Consumer is core defining feature whenever creation pattern is Factory Method or Abstract Factory. If Client and Consumer are same class, then it is Factory method, if they are different, it is an Abstract factory. If so, why can't the Creator method in the Factory Method be put in a separate class? You just created Abstract Factory ...


0

Your distinction is not generally correct. For example, the Abstract Factory Pattern uses the Factory Method Pattern. In the Factory Method Pattern, the classes using and providing the factory method need not be the same class. An Abstract Factory class has object creation as its sole concern. If an abstract factory instance were its own client, this would ...


0

By having a method in Factory Method, you make it easy to customize the behaviour of a single class by simply deriving a new class from it and overriding a single method. This is simpler than needing to create an entirely new factory class to perform the same customization. However, if multiple classes need to be customized the same way, using a separate ...


3

You seem to be mixing two very different concepts: Separating presentation and business logic (MVC) => increase maintainability Assigning execution to a node => increase efficiency Back in the days Client/Server computing was often confused to imply the first because clients generally did not offer much computing power, as compared to servers. So it ...


2

Because users have always wanted the same functionality, bells and whistles with their web apps (not just web sites) that they had with desktop apps. Making this all run in a browser (actually multiple browsers) isn't like the old days when you could link a VB form to a database with little code. This is easier to accomplish when you don't have to make trips ...


47

Shifting the computing load between the server and the client is a cyclical phenomenon, and has been so for quite some time. When I was in community college the Personal Computer was just getting a head of steam. But Ethernet was not in widespread use yet, and nobody had a local area network. Back then, the college had a mainframe that handled student ...


7

At some point, every project becomes too large and complicated to keep it all in your head. For some this point comes sooner or later than for others and you seem to have hit that point in your project now. The first step now is to start writing that dreaded documentation. Write down what each class is supposed to be doing, which classes work together ...


2

Well it actually depends on the stuff. If the stuff is related to the business logic of the application and inside has to do with domain objects then it has to go in another class and be aggregated in the services or depending on domain in a superclass of both services. For example both services need to check if a user already exists. On the other hand if ...


0

Adapter When you have incompatible interfaces, that perform similar logic, to adapt one into the other, so that you can use implementations of one with things that expect the other. Example: You have an object that wants a Car, but you only have a 4WheelVehicle class, so you create a CarBuiltUsing4WheelVehicle and use that as your Car. Facade When you ...


1

You can use a "parser generator" like the excellent and Java-native ANTLR for this. In fact, ANTLR has some SQL grammars already available for use here: http://www.antlr3.org/grammar/list.html



Top 50 recent answers are included