Tag Info

New answers tagged

0

Can you create a dummy record in the database with the default values, then pass a flag to the edit page to indicate it should create instead of update on save? If it's not possible to pass a flag, would it be possible to give the dummy record a unique ID that you would then hard-code into the edit page to indicate that the record should be created instead ...


0

Working out a winning strategy to this game is going to be a very hard problem and it will probably turn out to be something like choose a 'high' card 34.6% of the time. consider the following game where timid plays bold B 10,9,8,7 T 1 ,2,3,4 at this point B has won 4 hands, but T is guaranteed win of 4 with his 7,8,9,10 which he has yet to play. It all ...


0

The advantage of strategy two is to minimize dll hell. Usually Company.Framework.Persistence.MySQL.dll will depend on some dll for interfacing with MySql. If I have no interest in MySql, Why should I download the dll from MySql? Lets say your framework supported 20 different storage providers. Most users only use one. So all users have to go and get 19 ...


0

If I understand you correctly, each player gets 10 cards numbered 1 through 10. During each round, the player picks one of his cards to match against the other player. Pretend for a minute that you are the bold player. You'll pick "8" as your first card, leaving you with 1,2,3,4,5,6,7,_,9,10. The human player will pick a number that's either lower ...


0

I do it that way too. Projects/dlls are essentially free and make the code more readable and easier to use. I have known people use a single large DLL and differentiate with name spaces. But as you say they have to deploy unused code, I don't see any benefits to the practice and many downsides such as change to one implementation requires recompile of ...


0

This is a tricky question. I do feel that architecture may help with the problem. From the evidence, it sounds like the .dll isn't loaded when the program is loaded. It almost sounds like a plugin. One thing that comes to mind is that you have to initialize the .DLL. The programmer has to assume that the object won't come back reliably, anyways. You ...


0

This is a common problem we encounter in our tools too. A nice UI solution we use is shown by a product by Telerek called Kendo. The grid can use a button to sync edits with the db inside the grid. Although the grid takes a professional license, you can try it out free and see if you like the style and follow the samples and build your own instead. ...


2

With the details given, i find difficult to justify the need for temporary implementation - ImplB. Anyway, am parking that here. As all the 3 are implemented for a specific purpose, though there could be added functionality for implC, I believe that there could be a certain abstract type for these 3 - interface or an abstract class. Once that is in place ...


0

The Web Ontology Language (OWL) implements a description logic with sameAs and other relations between descriptions of entity types as a solution for this problem. 'Description logic' is arguably the design pattern for two-way mappings, as other representations are sub-sets of what a description logic can describe. If the mapping is single way, then there ...


0

Among other things (a template engine, an OO language, an application container etc. ) php functions quite well as middleware. A simple php class/script that maps your functionality to php classes or scripts or resources would work fine. ( After all this is the paradigm used by the most successful and admired Python frameworks!) Java, J2EE etc. need ...


1

(Disclaimer: I don't know any of the technologies mentioned in the question; I'm just inferring from the descriptions on the question itself and the linked articles.) Dependency and the order of execution. Based on the linked documentation, It seems you can control the order of execution of middlewares simply by calling app.use(...) in a particular ...


0

I have experience with big CRM/ERP product created this way. It is doable, but takes considerable more time and functionality will be limited. If this kind of thing is proposed only for access control, I don't think it's worth it. Some downsides: All types of controls you want to use, must be custom coded to support persisting info into database. If it is ...


0

A quadtree (or octree in 3 dimensions) is also good for spatial indexing.


2

Is this an appropriate use of the Singleton pattern, or are there still some pitfalls that I'm missing? No, this has almost all of the pitfalls of singletons and even that assumes that you actually use Supplier almost everywhere and have other implementations. I'm not going to go into the various pitfalls of singletons as they have been covered well ...


2

What you are looking for is not a singleton, but a factory. The reason is you have a single object that figures out which logic to execute, then executes it. As you say in your comment, it is functionally similar to a switch statement: figure out which branch to execute, then execute it. That works fine if your logic is simple, but once it grows in ...


0

It seems slightly odd that Example.attributes can contain a mixture of AttributeA and AttributeB objects, but ExamplesAndMore.examples must contain a 'homogenous' (using that loosely) List of Example objects. How are these supposed to be used, for both Example and ExamplesAndMore classes? Is there also some kind of implied ordering/equivalence between the ...


2

What you could do is a variation of an Abstract Factory. Something like this: public class ProtocolFactory { public IP _protocol; public ProtocolFactory(IP protocol) { _protocol = protocol; } public IA GetAService() { return _protocol as IA ?? new NoOpProtocol(); } public IB GetBService() { ...


1

This depends a great deal on the nature of the PDFs you accept as input. If you have control over the format of the PDF you're accepting, you can very easily extract the data you need; on the other hand, if you agree to accept any valid PDF at all, your task will be much harder. A loose hierarchy of options that PDFs can provide: PDF forms are designed ...


0

Calculate the distances between zip codes once and cache them. Keep the restaurants list sorted by the distance to the user. Enumerating the restaurants starting from the smallest distance you can detect the point when the restaurants go out of walking range - at that point you can ignore the rest and break the loop.


0

Meet BoxPong, a very simple game I made to get acquainted with object-oriented game development. Making BoxPong helped me formulate, among other things, a fundamental question: how can I have objects that interact with each other without having to "belong" to each other? I have quite a bit of experience writing code for the SNES, where you have ...


2

You have really two options here: factoring - isolate interfaces of each object and use soft casting (as operator) to determine extended capabilities of the class optional feature pattern - implement all methods available on all classes in one base class and throw NotSupportedException when the given function is not supported. Both of those have their ...


4

In general, it turns out very badly if objects of the same level know about each other. Once objects know about each other they are tied, or coupled to each other. This makes them hard to change, hard to test, hard to maintain. It works out much better if there is some object "above" that knows about the two and can set the interactions between them. The ...


6

You've discovered the need for spatial indexing. R-trees are probably the most common approach. The basic idea is a tree structure with rectangular bounding boxes computed over all the children of a given node. That way searching for a region or a point can traverse the tree, pruning out any parts of the tree (most of it) where the bounding box is not a ...


0

I think the "should a directive interact with a service" question depends on what your service is doing. I've had directives interact with services that don't do anything with HTTP requests and I think it's a good pattern. Services/Factories are great for encapsulating more data oriented logic, and directives are great for encapsulating presentation ...


3

Dependency Inversion should be best fit in your case. The interfaces should not be defined based on supported capabilities, but on what P_User is expecting from the protocol. Each protocol can then implemented what P_User needs based on it's capabilities.


1

Big difference between Active Record and Repository patterns is in my opinion the owner of the link between entity instance and underlying storage: in Active Record, entity instance knows how and where to persist itself (this is what "active" means in my mind). That's why you can just call user.save() and it persists itself. in Repository pattern, entity ...


1

If you were to notice something was not working in a unique program, a bug, what would be your next step in correcting? You want the bug to happen again, so that you can see it for yourself (as opposed to just being told by other people). This is called reproducing the bug. Often, you also want to run it in a controlled environment, where the bug can't ...


1

So I'll try to answer a few of these points. Depending on the severity and stupidity level of the bug, I could patch it quietly and push it into the next update, providing info on the corrected bug, or inform everyone LOUDLY that the program may be giving out wrong results/deleting your stuff/whatever and then push the update. That depends on what your ...


-2

On a program that you thought was working, the first thing you're likely to do is to try the same thing again (assuming that the problem was that you made a mistake in operating the program). Next you might try re-running some old data, for which you know for sure the "correct" result. The very last resort is to go back to look at at the source code, ...


4

Some opinions: If I were to notice something wrong, depending on the criticality of the bug and the service itself, I may decide to not do anything, or may decide to bring it down immediately. It's all relative, and a judgement call. Some bugs can wait, but others that run afoul of regulations or are security risks need to be addressed immediately. It ...


10

This is a remarkable question. Let's see: If the program is in production (in use by customers) you would have to take it down, inform customers or take whatever measure to ensure abuse is stopped. You might take down your sales page. In order to ensure the quality of your program, you might try updating the program if that is possible "over the air"; this ...


2

No, a builder is not unheard of for building messages. Spring Integration does something similar with a Builder. Spring Integration messages have a general structure like yours: a payload and a header. There's the Message interface public interface Message<T> { T getPayLoad(); MessageHeaders getHeaders(); } The MessageHeaders class (your ...


0

I would recommend (d) have your voting function return a result saying whether it was successful or not. Whatever mechanism you use for voting can fail, the user should be informed if that happens. public bool vote() { if (!can_vote()) { return false;} // take whatever action you need to, prefer functions that signal failure return true; }


1

The repository pattern: Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects. The Data Mapping layer that you've chosen is Active Record. Ergo, the Repository is that software pattern that provides an additional layer of abstraction between your Active Record pattern and your business ...


3

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


1

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


3

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


2

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


1

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


4

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


3

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



Top 50 recent answers are included