Tag Info

Hot answers tagged

11

The problem you are addressing is quite fundamental. I have experienced the same problem when I worked for a company that made a large J2EE application that consisted of several hundred web pages and over a million and a half lines of Java code. This code used ORM (JPA) for persistence. This problem get worse when you use 3rd party technologies in every ...


7

The problem is that you've effectively created a global variable for accessing these objects, the Foolist class. This has drawbacks for things like testability and is in general just poor design. Global state doesn't help make code easy to read and the consuming classes can never be isolated from the Foos (look up mocking) d when testing. Avoid the static ...


7

The problem you facing is an old one: code for persistent objects often looks similar for each class, it is simply boilerplate code. That's why some smart people invented Object Relational Mappers - they solve exactly that problem. See this former SO post for a list of ORMs for PHP. When existing ORMs do not suffer your needs, there is also an alternative: ...


6

When the HTTP request is completed, it will return some data, and the model gets updated by the responsible part of your system. Then raise an event which tells everyone who subscribed to it "new data has arrived", but do not pass the actual data in this event, only the relevant information for the subscribers which part of the model has changed. The event ...


6

To me it seems you have a solution looking for a problem. Is there a name for splitting interfaces by accessors and mutators into separate interfaces? This might be a little provoking, but actually I would call it "overdesigning things" or "overcomplicating things". By offering a mutable and an immutable variant of the same class, you offer two ...


4

The selling points of the Pimpl pattern are: total encapsulation: there are no (private) data members mentioned in the header file of the interface object. stability: until you break the public interface (which in C++ includes private members), you'll never have to recompile code that depends on the interface object. This makes the Pimpl a great pattern ...


4

The answer may be simpler than you might have originally thought: replace the "Countries" table shared across monolithic database-centric apps with a microservice, or simple webservice that exposes the same functionality with a simple REST call (note: I'm suggesting REST though that is not your only option, though it is probably the lightest-weight option). ...


4

Fundamentally, there's no problem described in the question that actually needs a solution. You've given no reason for a Foo holder to exist, or what it should be able to do. So really, FooList is completely useless. If you need a Foo, there's a language feature for that- new Foo(1). There's no reason for any additional holding to be baked in to the Foo ...


3

As indicated in the comments, there is no mixed usage of algorithms from the different families. If there is no use-case where an IAlgo can refer to either an AlgoAN or an AlgoBK instance, then there is no reason to have a shared interface for the various families of algorithms. The best way forward is to introduce a new interface for each algorithm ...


3

In general: User logs into some authentication system. Authentication system provides a token that effectively says "Authentication System X asserts that you are Bob, until 3:00 PM 8/31/2015 UTC". User then passes that token as metadata (header, some data envelope) to the various APIs. The various APIs look at it and decide if they trust Authentication ...


3

It depends. When A and B obtain their data each on its own, this has the advantage that both are independent from each other, and A may be used without B, and B without A. The disadvantage is that you might need to pull the same data over the network twice, and that the data displayed by A and B might not be always consistent because the content changed ...


3

I see a few options depending on what you need: (1) if there are many unique instances that follow a common algorithm, (2) if there are many similar objects or you will generated objects at run-time, and (3) if you want to dynamically modify the object's behavior while running. Note: you can combine all of the patterns I mention here, if need be. If each ...


3

First of all, I wouldn't approach a clean architecture in PHP. One of the main goals of clean architecture is to allow the user interface to be considered as essentially a plugin to the application, allowing you to change between types of UI easily. By going with PHP you are restricting yourself essentially to web-based interfaces. If you are familiar with a ...


2

TL;DR: Different subtype constructors are not only ok, they are expected. Liskov directly addresses the usage of different constructors in her paper Behavioral Subtyping Using Invariants and Constraints which is the formalization of the principle. "..omitting creators [from the type specification] makes it easy for a type to have multiple implementations, ...


2

I would leave them completely separate. Services and servers (notice I carefully separate the abstracted hardware and the abstracted software) are separate things. I would let each Service object have one Remote (or VMInstance or whatever you want to call it) property, possibly passed in a contructor, that could potentially be changeable (service ...


2

In general, when you are doing object oriented programming, you want your data and behavior to be together (in one class). You also want to achieve high cohesion with your classes. This means that most/all of your methods use most/all of the attributes in your class. This will help you achieve the single responsibility principle. Low cohesion means that ...


2

I have the feeling that you are over-thinking this. How would you model such a system inside a Java standalone application? What would be my service and domain classes etc.? There isn't much to speak of here. RegEx the hell out of each line to get that PIN code either as String or int. Depending on what type you use for the PIN use either ...


2

Most dependency injection containers can be configured to create the dependencies as well as inject them. No need to have a separate process to create dependencies. Here is a simple example using the PHP Pimple container(http://pimple.sensiolabs.org/) // This is the importer service definition $dic['arbiter_schedule_importer_games_with_slots_xml'] = ...


2

Keep your DTO's simple You are right that having a command with 9 arguments in the constructor is ugly. But do you really HAVE to put those things into the constructor? Make your fields public, create your command with an empty constructor and just assign to the fields. The point of constructor arguments is to have guaranteed valid entities, since you are ...


2

To me, the advantages don't outweigh the disadvantages. Advantages: It can speed up compilation, since it saves a rebuild if only the private method signatures have changed. But rebuilding is necessary if public or protected method signatures or private data members have changed, and it's rare that I have to change private method signatures without ...


2

How about simplifying the call to virtual int matchCount() by removing all arguments, and instantiating each Strategy with the arguments of the matchCount method in your question. Then you inject the concrete strategy into your Context. Here are some ways to use the strategies (I'm not sure how it works in your real problem because there are no details in ...


2

The benefit of immutability is that it doesn't matter as much what you do with your references to it. Globals, static classes, and singletons are much less problematic than their mutable counterparts, because you don't have to synchronize mutations and track the order dependencies that creates. However, they still have the issues with mocking out for unit ...


1

It looks like you want to spool the result of HTTP requests. Indeed, you might use some caching HTTP proxy like squid (you might use it, instead of coding your own). You could use both HTTP client libraries (like libcurl) and HTTP server libraries (like libonion) in the same process (but probably in different threads, or thru some event loop like libev or ...


1

List<String> parcelList = new BufferedReader(new InputStreamReader( inputStream, StandardCharsets.UTF_8)).lines().collect( Collectors.toList()); Welcome to the world of Java 8 and stream-based operations! This means that the subsequent explicit looping using a parcelListIterator is unnecessary... you can simply daisy-chain your steps as such: try ...


1

Should, for example, each tile store the data of its reward or there should be a reward manager for checking how many tiles are consecutive next to each other to give the reward to the player? How I would do it You have a Reel object that can be spun randomly You have a number of Reward objects that have a threshold required to win, and a prize amount ...


1

Classes are often used for concepts, to hold together all the attributes of the concept and the interactions that are possible. When deciding what to do however, it's purely a matter of what works best, and what design is the best. When you are deciding what to do I'd go about it this way: If the calculation is part of the (to be) object, make a class for ...


1

This would work, but it's a very unusual way of accomplishing this task, so I would avoid it unless it's meant to be part of a learning exercise in how prototypes work. Just to make sure we're on the same page, the "typical way" I have in mind is this: var Switch = function() { this.state = "ON"; }; Switch.prototype.switch = function() { ...


1

This is a very similar approach I've take using Amazon SQS, with a few differences to overcome a few potential downsides; if a message becomes available just after you check, you'll be waiting 100 seconds before taking another peek, which is not particularly responsive. If many messages arrive in quick succession, you may not be able to keep up with them ...


1

If you are 100% sure you want to "bolt on" methods onto these EF table/classes, then just open them up as partial class in a separate file and add the methods needed: // location -> /EntityPartials/Person.cs public partial class Person { public void SayName() { SomeExternalAssembly.Say(this.Name); // 'this.*' above is optional but could be ...


1

I recently made an implementation of the ASP.NET 5 Identity-framework which was a pain in the butt, it has its UserStore (and RoleStore) which is kind of annoying to implement. My implementation can be found here, it might give you a few ideas! This sounds sort of like the same thing. You need a base class where different type of profiles(?) can be ...



Only top voted, non community-wiki answers of a minimum length are eligible