Tag Info

Hot answers tagged

16

So am I missing something important here? YES While these look like the same thing, and represent the same thing in the domain, they are not the same (OOP) objects. One is the Order as known by the data storage part of the code. The other is the Order as known by the UI. While it's a pleasant coincidence that these classes have the same properties, ...


15

Builders are most useful when your object needs a lot of arguments/dependencies to be useful, or you want to allow many different ways of constructing the object. Off the top of my head, I can imagine someone might want to "build" objects in a 3D game like this: // Just ignore the fact that this hypothetical god class is coupled to everything ever new ...


12

In my experience, a web application would have to be trivially small to not benefit from the organization and decoupling that MVC provides. Perhaps a bit of explanation about the MV* family of architectural patterns is in order. The MV* patterns concern themselves primarily with the User Interface. Their primary purpose is to provide decoupling between ...


8

You're describing Acceptance Test-Driven Development. The basic principle behind ATDD is that each software requirement is accompanied by an acceptance test that, when executed, provides proof that the requirement has been satisfied. Acceptance tests are created when the requirements are analyzed and prior to coding. They can be developed ...


7

The purpose of the View Model is to provide decoupling in two ways: by providing data in the shape that the View requires (independent of the model), and (especially in MVVM) by pushing some or all of the View logic back from the View to the View Model. In a fully normalized model, Customer would not be represented in the Model by a string, but rather by an ...


5

Your scenario seems like you have placed an entire "message processing subsystem" inside a single function. In order to simplify the function, you will need to come up with an actual message processing subsystem consisting of several classes. Some, if not all, of these classes will need to be instantiated, allowed to run, and discarded on each invocation ...


4

One thing the Visitor Pattern does that is often not talked about, is enabling to choose which side of the Expression Problem you want to tackle. So, what is the Expression Problem? It refers to the basic problem of extensibility: our programs manipulate data types using operations. As our programs evolve, we need to extend them with new data types and new ...


4

Which class should know how to convert a new A to a legacy A? Maybe it's the A class itself which has this knowledge. It may know how new and legacy values are mapped, which fields should be added or removed, etc. In this case the following approach seems quite natural: A legacyA = a.toLegacy(); The benefit of this approach is consistency: it's similar ...


3

Is the top-down design methodology I am describing here a valid approach? Does it have a name? Yes, it is called top-down design, and there's a decent Wikipedia article. In particular, you're describing an informal variant where you figure out what you want the library to do and how you want it organized based on how you intend to use it. do teams ...


3

God object is one of the worst "designs" you can create. Please, put some effort into separating different concerns. Your future self will thank you.


3

In addition to what Ixrec said, the constructors or method named parameters won't allow you to have your object in a to-be-constructed state in which it can still be modified before building it. This is the beauty of the Builder, where you can delegate parts of its construction to different methods or classes altgether: var myThingBuilder = new ...


3

Short answer: No. Long answer: Think back to the Single Responsibility Principle. An object (or method, or module) should only have one reason to exist. That reason may be large or small, but it is cohesive. A memento exists to manage temporal state. In other words, track state as it changes, to allow moving backward and forward through those states. The ...


3

"Red arrows mean it create pointed class as a object and call the method of it." So you did not separate creation from usage? This is pretty much opinionated, but one "recommended" way of creating OO programs, especially when multiple classes are involved, is to make use of dependency injection. One central aspect of DI is: if one object needs another ...


2

I understand that in React state should only contain data which may change and cannot be computed from elsewhere, I think there is no need to store something that cannot change in a variable at all (use constants for that). And if something can be computed from elsewhere, you might wrap calculation into a function and call it when you need. So, this ...


2

To get an object by name, put your objects into a Dictionary. var dict = new Dictionary<string, CardInfo>(); There are a number of ways to add the CardInfo objects to the dictionary. Here's one: dict.Add("cardname", new CardInfo { foo = 1, bar = 2 }); You retrieve them like this: var cardInfo = dict.Item("cardname"); or var cardInfo = ...


2

This boils down to composition vs. inheritance. Let's take a look at one pattern that you can do in both ways. The adapter pattern is, as the name implies, an adapter between two classes that are otherwise incompatible. Say you write a 3D engine and you need a Point class. You have your Point all ready and it kind of works, but then you find another class ...


2

In some respect you are right: They both refer to the same domainobject, which is called order. But you are wrong in as far, it is not a real duplication than a different representation - originated from different purposes. If you want to persist your order, you e.g. want access to each and every column. But you do not want to leak that to the outside. ...


2

I'd go with the second approach, with a change which releases the handle when done. If each method takes care of getting, operating and releasing its own handle, then your application should be better suited to scale up (assuming you have some sort of pooling underneath). With the first approach, it is hard to say what will happen should two different ...


2

Generally speaking, there is no right way to organize classes. There is only the way that best meets the projects requirements for clarity. The size of the modules is probably the least important organizing principle. – Robert Harvey


2

Modular design is about separation of concerns, NOT about splitting something up into smaller sections (though it tends to have that effect). It's perfectly acceptable (and even very good practice) to have a separate EJB module, web module, etc.. Each is its own deliverable after all within the JEE landscape, with the EJB module creating an EJB jar, the web ...


2

In the MVP pattern is the View is "dumb". It doesn't really do anything. The presenter acts as the controlling object in the heirarchy, while the Model stores the data and has business logic methods on it. That doesn't preclude the View from firing events, which are hooked by the Presenter to methods or properties on the model, or to other testable logic ...


2

This is issue of following the Law of Demeter. In first case, the Main class knows about all the other classes. If it has dependency on all of those classes, then you have to check if Main works properly if you change any of those classes + the one that is using it. If you needed to mock dependencies of Main class, then you would have to mock all of those ...


2

some options are: using immutable trees as basic data structure using a builder or mutation operations to construct a FooTree without needing a Tree copying the input tree (which is good practice unless you have really big data and performance issues) Note that by builder I mean the builder pattern as described by Joshua Bloch. (Long article, but the ...


2

Have you had a look at existing libraries e.g. spring quartz or spring batch (I'm not sure what fits your needs most)? To your question: I assume the problem is, that you want to persist some metadata to the task in a polymorphic way, so an e-mail task has e-mail addresses assigned, a log-task a log-level, and so on. You can store a list of those in memory ...


1

There is no "correct" in programming. There are good things, there are bad things, but more often than not there's a series of tradeoffs that are some good and some bad. Even if you made code that did the job and mislabeled it the strategy pattern, that doesn't make the code incorrect; it just makes your communication confusing. Rant aside, using this in ...


1

A class is a blueprint or template or set of instructions to build a specific type of object. A object is a instance of a class. So a class patterns plays with things you can do with classes like abstraction, inheritance, interfaces, visibility scope, etc. A Object pattern plays with things you can do whith instance like references, pointers, creation and ...


1

If I understand your question, the Facade Pattern fits your needs: Intent: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. Wrap a complicated subsystem with a simpler interface. Your Facade, the ClientReport class, has classes SourceA and ...


1

Here are (at least) two objects client and report involved. From what you write so far, a report seems best to be composed of a client and ressources: public class ClientReport() { public Client client; public decimal ressources; public getClientName(){ return this.client.getName(); } // ... public setRessources(decimal ressources){ ...


1

The definition of your client class should not be tied to how you acquire the data to construct the class. You should review your business requirements of your client class and define it based on that only. From what you have shown so far, it looks like you need two file processing classes which both are provided a collection of client objects to work on, ...


1

An application context object usually allows access to the configuration of the application instance, things like: What is the application's hostname and path? How is dependency injection configured, i.e. what implementation is to be used for a given interface? OS environment variables In a properly designed OO system, the access will be via methods of ...



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