Tag Info

New answers tagged

1

First of all, this is not a "problem" which needs "modelling". This is just a syntax issue. Secondly, why on earth would you even think of using a builder pattern for this? Is it perhaps because you read "Clean Code", where on page 35 the author classifies methods into four categories, depending on whether they accept zero, one, two, or the incredibly ...


1

In addition to the other drawbacks that other answers have posited, another is that the Throwable mechanism is designed to be overbearing i.e., it short-circuits normal processing wherever present. Imagine the following public void doSomething(){ Foo it = new Foo(); Bar something = it.doesSomething(); //anything thrown here will cause a hard stop ...


0

Would it be abusive to create an event system that uses try-catch statements and throwables, which are really made for error handling? Abusive is an emotionally loaded term. And it is blatantly subjective ... unless you are measuring a standard that everyone concerned can agree is applicable. What could that standard be? It could be a particular ...


2

I don't understand how would something like that work. After a method throws an exception, it stops executing and permanently gives up control to some exception handler. But after a method raises an event, it gives up control to the event handler only temporarily, and then continues executing. I don't see how could you emulate temporarily giving up control ...


1

Neither is inherently better than the other. Use whichever one is more readable. In your example, where you can get all the values immediately and construct the object in a single object literal expression, I see absolutely no reason not to do just that. If getting each property was a non-trivial exercise, or there are many properties the final object may ...


1

There is no "correct" way of doing this as either will work just fine. It depends entirely upon what makes your code the easiest to write, understand and maintain. If I already know the values of object properties at the time of declaration of the object, I find it generally makes the code a bit more self describing if I just put the known properties ...


1

Smart data structures and dumb code works a lot better than the other way around. -- Eric S. Raymond, The Cathedral and the Bazaar You can use XML or JSON with schemas. Validation rules should be machine-readable first, and human-readable if possible. Consider not inventing your own format and using XML Schema or JSON Schema instead. Switching to ...


0

That is a great question and an interesting problem. I propose that you use a combination of Chain of Responsibility and Double Dispatch patterns (pattern examples here). First lets define the task hierarchy. Notice that there are now multiple run methods to implement the Double Dispatch. public abstract class RecurringTask { public abstract boolean ...


2

I would say Option 1 is the best route to take. The reason you should not dismiss it is that the SendEmailTask is not an entity. An entity is an object concerned with holding data and state. Your class has very little of that. In fact, it is not an entity, but it holds an entity: the Email object you are storing. That means that Email should not take a ...


0

Outputting results embedded in the TestScript Description seems excessive. If the results thus written are preventing the TestScript Description from being reused without an edit to remove them, then, the architecture is silly. Output specifications belong in the Description. The typical test pattern I've seen all my life is that the test has a name, that ...


0

I completely disagree with that article. Services (concretely their "API") are important party of the Business Domain and as such will exist within Domain Model. And there is no problem with entities in business domain referencing something else in same business domain. When X send mail to Y. Is a business rule. And to do that, service that sends mail ...


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 ...


2

For the most part, you can write very Java-like code in JavaScript, but it's usually simpler not to. There are two pretty major factors that affect your design: dynamic typing and functional-style callbacks. Dynamic typing means you don't use interfaces, and you don't need to create a lot of those little classes that do nothing else but implement ...


-1

Note how the input is a Free DSL a, for any type a. The only way to produce that with out particular DSL is by ending the expression with End—which guarantees that we can't forget to close the connection once we're done. Not true as shown above. In this form the caller can pick any type for a.


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

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

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 ...


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 know it's an oldish question, but check out ReactiveX if you haven't already. I discovered it recently, and it's really changed how I see designs like these. It's basically a combination of type-safe observables, event-based push (sync or async), and classic pipes-and-filters. http://reactivex.io/ You just write little components and snap them together ...


0

You seem to be asking for two different things here: changing the values of some fields Are you referring to how you need to normalize values' formattings ("yyyy-MM-dd" to "ddMMyy") or possibly even data types here (BigDecimal to int)? If so, I'll suggest creating a conversion class to handles these, so that you can safely eliminate both the ...


0

Have a history table storing all updates like in Wordpress with a version number. Yes, but store not updates, but complete revisions (contents of each edit). If you need to save space, compress it. But don't care too much about the size. Humans are rarely capable of producing large volumes of data by themselves. There are many libraries, that can ...


1

You could have a factory which provides the correct adapted object. Exposing a series of classes or a single class with multiple methods assumes that you have some knowledge before hand of the system. Another (problematic, I think) issue is that by exposing all the adapters you are giving the caller (client) complete control over which adapter gets called. ...


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 ...


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

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


1

The purpose of the MV* patterns is primarily to provide separation of concerns between the UI and the rest of the system. Your Audio Player Service, if it also includes the player, uses the entire pattern. If it's just streaming data, it's the model.


1

I am still years away from fully grasping the distinction between an abstract class and an interface. Every time I think I get a handle on the basic concepts, I go looking on stackexchange and I'm two steps back. But a few thoughts on the topic and the OPs question: First: There are two common explanations of an interface: An interface is a list of ...


1

ONLY for those pessimistic guys whom enjoy fussing instead of guiding: This is NOT a homework, but just a personal pry! Anyway I succeed to solve it using the following approach: 1 - Suppose that we have only one disk (n=1), we can move it in two steps from 'A' to 'B' using 'C' (recursion point). If we have more than one disks (n>1): 2 - Move n-1 top ...


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 ...


1

Is having Purchase on Customer consistent with OOP principles and good design? Or is there a better place to put it, do we need a new class? No, it is not, and yes you need a new class. A purchase indicates that there is data to be persisted, and the Customer object should not know about data persistence pertaining to an order, or even about what is ...


0

I would post the whole function to code review. But, here are my views on your snippet and questions from an OOP view point: static ProcessMessage should be message.GetTransformedAttachments() and TransformedAttachment.Process() if (logic) should be attach.IsLogicTrue TransformedAttachmentData(attach) should be attach.GetTransformedData() So thats 3 ...


1

I designed and implemented a hierarchy like this many years ago (before generics) so here are some comments. They may help stop you from repeating my mistakes :) The proliferation of methods like parseNumber(), parseName() suggests that the class hierarchy needs adjusment, yet your hierarchy looks well designed. My approach would be a combination of ...


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 ...


0

Single Responsibility Principles says that each software module should have only one reason to change. On a recent article Uncle Bob explained "reason to change", However, as you think about this principle, remember that the reasons for change are people. It is people who request changes. And you don't want to confuse those people, or yourself, by mixing ...


0

Seems like a viewmodel problem to me. In WPF (the MVVM framework I'm most familiar with), the view handles everything related to rendering and composing view elements in a domain agnostic way. It knows how to render a textbox, or draw a line across a canvas, but it doesnt know that this line is from layer 1 of my document. It knows lots of ways to draw ...


-3

I think MVC is used just a buzzword by theorists that are managers. However, having said that, the current iteration of the web with HTML5 prevalent, responsive design, and trying to create a single line of database programming that will work on the web and on an iPhone lends itself to the general ideas of MVC. The web front-end technology is literally ...


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 ...


1

It's unclear from the question if remote repo doesn't support add/update operations at all or only for specific types. In case of the first option, I would go with 2 interfaces: IReadonlyRepo, IWritableRepo. In case of the second option, I would go with the exception approach.


1

tldr; 1) Yes, there's a better way. 2) Yes, you shouldn't be firing an HTTP request in an ng-repeat Full Answer You need to understand how ng-repeat works. Every single time the digest cycle runs, angular checks to see if the array in the ng-repeat has changed. And when you work with angular, I'd recommend that you think of the digest cycle as something ...


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 ...


1

The Wikipedia article for State Pattern has a Java example that illustrates two states, involving two different methods. Those methods can be arbitrarily complex, so I consider a two-state solution (no pun intended) perfectly valid. interface Statelike { void writeName(StateContext context, String name); } class StateLowerCase implements Statelike { ...


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

Let the View directly subscribe to the ObjectAEvent event. We've now coupled the View into the internals of the Model, which I believe violates the Law of Demeter. I'm pretty sure this also violates the concept of MVC by definition. MVC isn't about total decoupling. It's about avoiding coupling to elements that are unstable. As for Law of Demeter, ...


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 ...


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. ...



Top 50 recent answers are included