Tag Info

New answers tagged

1

If your personal opinion is already that it is too much work, then yes, look at ways to simplify the design by merging or omitting certain classes. Some things to consider: Merge the entity and the business classes. If it can be done in a 'clean' way with your ORM framework. Be adaptable. For some crazy classes you may benefit from all this infrastructure ...


1

On first sight, I find your architecture overly complex. What is the purpose of having a Person(@Entity), a ServiceRequest, ServiceResponse, DomainServiceRequest, DomainServiceResponse besides sleeping good at night with abstractions for the abstractions sake? You are drowning little puppies here Within the Backend of your application, using only the ...


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


0

There are many considerations around class design, intelectual control, cohesion, future extensibility of the application, etc. My reccomendation on class size is focus on good functional cohesion and let the class size be what is natural. But, consider this variation on option B( or A?): you have broken down your business logic in to discreet functions ...


0

I'm against having large classes, even if all the methods are related, it makes more difficult to understand the code. So I vote for the [B] approach, where you pass the parameters to the constructor and the class implements an interface. This way, you can treat all classes as if they were of one type (interface type). You can handle the business logic ...


0

Did you look at role-based permissions? One controller, one route, returns/accepts different results depending on a user role. E.g. a GET request to http://blah.com/tickets will return all tickets if requester is an admin, or user's own tickets otherwise. A post to this route will return 200 for user, but 40x error (405 would fit here, I think?) for ...


0

Easy. Pass the table name from Book (and all other concrete classes) into a constructor of the abstract class. Store the table name in the abstract class and use it directly where needed. Remove the getTableName method Sorry my answer is so brief, I'm editing in the mobile app.


0

Maybe. There are exceptions to every rule, and no rule should be followed uncritically. You example might conceivably be one of the instances where it makes sense to swallow all exceptions. For example if you want to add tracing to a critical production system, and you want to make absolutely sure that you changes don't disrupt the main task of the app. ...


1

It really depends on the context in which you want to invoke those functions. [A] assumes that the arguments of your method are always well known in the section of code you wish to invoke it. You should use a static method for these types of stateless calculations. [B] assumes that the arguments/state of the code is different depending on some other ...


1

I think you can adapt the visitor pattern for your requirement. Your Book class should implement an interface, typically named Visitable. public interface Visitable{ public void accept(Visitor visitor); } Now, to your book class you pass in a visitor which performs the necessary operations. Implement this method in book class. public class Book ...


0

This would work if you dropped all the statics from the base class, and the abstract from the method with an implementation. Think of how the methods would be called by clients: either aBook.dropTable() or Book.dropTable() makes sense, but DatabaseObject.dropTable() doesn't; which table did you want dropped? Doubtless there are better ways to do things, ...


2

Since you wrote in your comment you want to make the output of the unchanged program stable when it is not changed between two runs, you already excluded "accidental changes to module variables" - without any changes, there can be no "accidental changes". The SO link you posted in your question mentioned how to initialize Python's hash seed to a fixed ...


1

I would add a bunch of unit tests for the individual modules and use something like Jenkins to compile and run the tests every time you make code changes. If you are finding variations when running, this should help you narrow it down so that you can change module logic to ensure repeatability.


0

While that's probably how it used to be before (and I do remember writing stuff like that myself), modern websites tend to use web frameworks such as Flask or Django or Ruby on Rails instead of static pages and rewrites. These frameworks include URL routing, where a certain pattern in the path, for example /artist/<name>, can be mapped to a function ...


6

I may be wrong, but your design seems to be horribly overengineered. To serialize just one Widget, you want to define WidgetReader, WidgetWriter, WidgetDatabaseReader, WidgetDatabaseWriter interfaces which each have implementations for XML, JSON, and binary encodings, and a factory to tie all those classes together. This is problematic for the following ...


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

You can create a comparator that compares the coordinates of the tile. In java 8 there is a helper function for that: Comparator<LCTile> cmp = Comparator.comparing( LCTile::getCoordinate, CoordinateComparator.instance); Then you can pass that with the list of tiles to Collections.sort.


2

I've found the following picture a good key for the difference between different measures (although undirected graphs are depicted, some apply to directed as well). Degree centrality [D] is straightforward: who has most in/out links. Eigenvector-centrality [C] captures the notion of indirect influence better. See Centrality on wikipedia for the definitions ...


0

Having methods return a new instance of their class is done for two reasons: Copying or cloning the current object Making the object immutable The C# language makes Strings immutable by having each method with a string return type return a new instance of a string. This allows you to modify data on an object and store the result of that operation without ...


2

It could be worse, but it's overly coupled, and a sign your do_stuff is too big. I would only do it if I needed the extra performance, and couldn't think of any other way. You didn't give us much to go on, but usually problems like that can be much more cleanly decomposed in the following way: common = [my_object.get_common() for my_object in all_objects] ...


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

I'd say that mutation inside a list comprehension looks unexpected and thus can be more error prone. On a code review I'd ask to rewrite it using an explicit loop which is typical for mutation. Also, you don't need [element for element in my_set] to transform a set to a list, list(my_set) suffices. You can also just iterate over a set as you'd do over a ...


0

Ideally the bank application should worry more about the account than the customer. For example, the bank should have methods like addAccount() : which will add account and create a customer implicitly if it is the first account of the customer and deleteAccount() : which will delete the account and delete the customer implicitly if it is the last ...


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


0

I have encountered this exact problem. I was not satisfied with the way I solved it, so I didn't answer your question right away. But on the other hand, neither does any of the other answers here. My solution: class IAlgo { virtual int matchCount(AlgoParameters *) = 0; } class AlgoA1 : public IAlgo { virtual int matchCount(AlgoParameters * ...


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


6

Trying to come up with an accurate taxonomy of the real-world objects you want to represent with a class hierarchy is usually not that productive. Your interfaces should represent functionality or behavior rather than ontological categories, because that's what interfaces are: one or more functions you can call. In other words, name the interface IEater ...


0

Optional arguments. Declaring the new arguments as optional allows you to add parameters and not break the existing code. Overloads. Split the strategy interface into multiple methods. Messages. Create a hierarchy of argument objects and pass them to the strategy instead of "loose" parameters. The mature calling code, will keep sending the messages, ...


2

What you're talking about is called a pessimistic offline lock. There are a number of ways of implementing them - the most common is similar to the way you propose, except instead of a background task to clear out the expired locks you simply clear them when you try to lock them and they're too old.


2

I think your solution is fine in general. It's an example of pessimistic locking and invaluable if you want to spare resources or process high-contention data. In your case, as the purpose of these operators is solely to process your customer requests, contention seems likely. So, you're locking the record ensuring that it does not appear in other ...


2

It's not uncommon to have methods that return the type of the class--how else would a clone function work? However, that's not what you are doing here. You have a class that returns a list of itself. I do not believe this function belongs in your Facebook class.


0

Using a Hash or GUID as Primary Key is also bad idea because it causes Index Fragmentation and frequent Page Splits.


7

I don't know if it is "wrong," but it certainly doesn't look "right" to me. I don't know why you are doing what you are doing. It looks like you are creating instances, but it's unclear if these are new instances or copies. If you are creating new instances, the usual way to do that is to use a static factory method. It's static so you don't have to have ...


2

You have to store your tasks, for instance in a db table, with at least the following informations: time_to_execute: timestamp of when task was set + delay in seconds to_do: things to do (this must be understandable by your backend) executed: 1 if the task has been executed already, otherwise 0 (default) Then, you need a scheduler, could be a cron, which ...


2

You can do this a few different ways. What you ultimately do depends on your server-side stack, your permissions on the server, and the nature of the side-effects needed for the delayed event. As I see them, your options are: An "embedded" scheduled task. If you're using a service-like backend technology (like a node server), you can put timeouts right in ...


1

A simple approach is to have a pending tasks table in your database. To create a task, add a row to the table that contains the action time, and any other data needed to process the task. You have a background thread that periodically queries the table, actions any tasks that have come due, and removes completed tasks from the table. I wouldn't describe ...


7

This former SO article tells you how to calculate the collision probability. For SHA-1, b is 160. The number of people living in austria is below 10 millions. Even if each living person in austria is registered in a hospital with a unique person/sector ID, that just makes a collision probability of less than 3.5 x 10^-35. I guess that should be small enough ...


4

Hashes will inevitably collide if they're smaller than all possible combinations of data. See this excellent answer: http://programmers.stackexchange.com/a/145633 If primary keys are not supposed to be meaningful (human readable; containing retrievable traits of data), I would just go with GUIDs. Yes, theoretically they can collide as well, but heat ...


0

Your design seems that it can benefit from Asynchronous Messaging Messages can be sent through different pipelines to multiple receiving applications and scheduled for execution at certain time (the scheduling can be a built-in feature of the message bus (middle-ware) or can be baked in your solution (reply with with a shceudled task id message and send the ...


1

Given that your application needs that kind of complexity, then here are my 5 cents (I will use Java code): Settings are split in two categories acording to whether or not they take immediate effect when they are altered. dynamic: have an immediate effect in the application's behavior static: don't have an immediate effect in the application's behavior ...


1

It's better (and less confusing) to have the empty [0] placeholder at the beginning of the array so that you can just plug the month directly into the array indexer, than it is to start January at month 0 and have to perform a bit of conversion math to get the correct array index each time. Sensible date implementations should not allow a month zero. Note ...


9

I'm not sure what you mean by "one and only one software!" but I think you may be reading too much into this document. Since it talks about what not how, it sounds much more like a high level requirements document for a system and not a single application. This is actually a very important document for any large project. I'm sure that if you were to look ...


3

You are a bit confused with how software documentation is developed. What you read is the requirements document. There are entire books written at length of how to engineer and document requirements, but all you need to know is that the requirements document specifies what the software is supposed to do. It makes no mention of how, since these documents are ...


5

Given immutability (which is often encouraged and said to be one of building blocks of functional programming) and CQS (which says that commands should not return a value other than void/unit), how do these work together? There are no commands in functional programming. Period. A function's result can only depend on its arguments, and it must be the ...


-1

As a graphic designer turned full stack web developer, for me this has so far been the easy part. I find that a lot of times there is a communication gap between a UX design team and the developers that implement the product. Sure, documents help, but the process can begin to feel a lot more natural once some face to face conversations about strategy occur. ...


2

You pretty much hit the nail on the head. Dependency injection is a great choice when you want to get dependencies that are known and unchanging at runtime or compile-time, depending on how you configure. Let's assume that you have a mailer in your application implemented by IMailer and you can use a TextBasedMailer or HtmlBasedMailer. You either build the ...


4

CQS is an idiom from object oriented languages that is designed to help avoid the confusion that can be caused when a function unexpectedly mutates state or interacts with the environment. This is not a problem for a functional language. In functional languages, all such interaction is explicit in the signatures of the functions involved. Hence, CQS serves ...


3

I would suggest using a facade object to hide the detail of the requirement for the decorator. The facade would simply create the service and its decorator behind the scenes, and then forward client requests to them. By presenting a simpler interface you make it easier for clients to use your service, avoid the need for a separate factory api and make it ...


2

If you explicitly save data, the best place to perform that is in a call at the end of the highest level method, the entry point to your service. That means you must divide your service methods into two categories, those that are public, entry level methods, and those that are internal methods, that should not save data.


0

Unless you have a strong reason, you should use an ORM (Entity Framework, NHibernate). When you work with an ORM, the objects that were returned from the database will be "observed" and you just run the "SaveChanges();" leaving the dirty work to the ORM; The ORM will automatically check which entities need to be persisted and if there is no change to be ...



Top 50 recent answers are included