Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

An alternative to building your own solution would be to use a ready made solution. There are queuing services that offer built in sheduled delivery. I know of Azure Service Bus. When you send a message or publish an event you can set the ScheduledEnqueueTimeUtc. Also, a framework like NServiceBus provides scheduled delivery on top of all the transports (...


0

There is no hard and fast rules how to handle errors. When an operation could (theoretically) produce an error, you need to look at the situation, each situation individually, and decide how to cope with it. Case 1: Errors that you are convinced cannot happen. Check for them, and in a debug version have an assertion that will stop execution in the debugger,...


0

This answer is based on the additional information from the comments. If the database is part of your system then whenever other system requests those data, your system has to offer them (let's disregard for a moment how is it done - this is true also if other system reaches directly to the database1). So from perspective of your system if other system asks ...


0

One use case? Don't stop there. What about systems without a use case? The ideal automated system has no use case. It just works. Anything that is used is semi-automatic at best. Your refrigerator keeps your food cool. Puting your food in and taking it out is independent from the system's behavior, that is not a use case. The cooling part is totally ...


1

Yes, systems can have just one use case. That is quite normal for systems with very specialized, automatic tasks and no real user. This reveals, however, that for such kind of systems, "use case analysis" does not bring you much benefit (except from the result there is only one). The purpose of this method is to split larger requirements into smaller ones,...


0

In this case you have one actor, the timer/scheduler. But you can say you have one use case with all the action involved or separate them, like scrap news, tag news, because this are complex operations.


0

If you've already decided (and I'd agree) to store the text in an another database and a key reference to it inside the graph edge, there's no need to store a copy of text there as well, that would just give you an overhead of having to provide consistency between the databases with no benefits. I'd place a caching layer in between the two databases (graph ...


2

Your ResourceCommonProcedures doesn't really seem to be an example of the Template Method pattern (as it doesn't really define a 'template' for an operation, except perhaps in a trivial sense). Your base class acts as a factory that produces a concrete ResourceCommonProcedures-derived instance based on an identifying parameter (resourceType). Arguably, that ...


1

One of the strong selling points of OO is supposed to be encapsulation: the implementation details are hidden away and only API, in the form of method signatures and the like, are exposed to the wider world. Yet there is a well recognised way of breaking that encapsulation: you guarantee that a method will perform certain actions, including calling other - ...


0

adding or updating info at the beginning of a text file involves moving all the rest of the file "forward" Only if you have a the simplest possible in-memory implementation. It would, for example, be easy to store a text file as a linked list of lines. Now, adding text at the start of the file is just a matter of prepending a new line to the linked list.


0

This may be a bad practise but you can store a value on app cache to make the token verification (iisue date, duration,user id). This could be a way (depending on the amount of users) and you have to delete expired tokens once a while.


4

Inheritance is not bad per se. It depends on how you use it. Avoiding a technique just because someone says it is bad is not a good way to make decisions. While I see where Josh Bloch is coming from, the alternative he proposes is not quite the same thing. The Template pattern aims to enforce a particular design; it takes advantage of the rigidity of ...


1

Make the generational nature of the data explicit: Create Databox1 from the initial set of values in step 2. Databox1 is immutable. Pass Databox1 to the next stage, producing Databox2; Databox2 either holds a reference to Databox1 or copies all the fields in place. Databox2 is immutable. Pass Databox N to stage N, and produce Databox N+1. The immutability ...


2

The risks First of all, there is nothing fundamentally wrong in using DTOs to carry the data between process, threads, or even functions. In principle, such DTOs should combine data belonging to well defined business objects, and follow clear transfer rules (e.g. from A to B; or from A to B with C enrinching it). But in your case, the all calculation ...


0

Yes, you can use UML, most notably sequence diagrams. With regard to the use of class diagrams, it depends on whether you design your application using object oriented design principles or not. If you have just a bunch of JavaScript functions, class diagrams don't add much. If you use JavaScript object prototypes to simulate a kind of classes, then these ...


1

[*caveat: I assume process -> concurrency] To me, there's no generic way to avoid illegal state because there is no general definition of 'illegal state.' Illegal states don't figure in Turing machines or the lambda calculus. If an illegal state exists, it exists via design. Illegal states are the result of a particular implementation of a particular ...


1

The right answer is complicated, but it seems to be no, depending on how you look at things. You may be talking about development time or execution time. I will talk only about execution time. You are implementing a state machine. The state machine, at any point of execution, has to have a current state. Transitions are triggered by the occurrence of ...


3

Stopping in a stopped state would just be a nop operations, so do nothing. No IllegalStateException need be thrown, just return immediately from the method if the system is in a state where the stop operation would be meaningless. Similar with the start operation. If the system is already started, it would be a nop operation. Of course for a more complex ...


10

You can avoid illegal states by starting in a legal state and disallowing transitions into illegal states. The problem is enforcing that in a system complex enough to get useful work done. The code you posted is trivial enough that it can be fixed simply by adding another type to represent your missing state. You seem to be using some Java like ...


2

Your understanding is pretty much spot on. But I wouldn't call it buzzword. It is more about some people trying to differentiate their process, values and principles from status quo. Having a good DevOps means that it is impossible to tell apart developers and operations. And that making a release from source code is as simple as pressing a button. Not ...


4

Illegal states are that, state. Compilers of most programming languages do not concern themselves with state, only with the types of states. So, to prevent those errors (or rather, raise them at compile time rather than at run time), you need to encode your state in a way the compiler can understand. For most general purpose programming languages this is ...


0

If you can compile the sources of the dependant system "d" yourself or if you can replace factory methods for "d"-dtos you can create java-interfaces for the used part of the d-dtos and use these in s instead of the original. This way s sources will only depend on your own interfaces instead of d-dtos


6

a design principle that could help me decide(support my idea) in this situation? System S shouldn't know System D exists. Pretend system D didn't exist. Now write data structures (POJO's, collections, whatever) that do what system S needs in the most convenient way possible. Now your adapters job is simply to convert the data from one systems form to the ...


3

If you want the best decoupling you must write your own POJOs, yes is more coding but is the way to go. If you're alright with the level of coupling and dependency of system D you can use his POJOs. But if you write adapters for limiting the coupling between the two system your must continue with your decision and write your own POJOs


0

I don't know if there is a name for this specifically. It seems like a simplified form of the Strategy Pattern but you could also maybe describe this as using the Decorator Pattern or a combination of the two. The simplest thing to make this thread safe would be to do this: class EnabledOrDisabledFoo implements Foo { private final AtomicBoolean ...


2

What you describe would only be feasible for void methods, getting something would need to return some default. To do that dynamically, one would use delegation and depending on a flag enable/disable the passing. There is a related technique: the lookup/discovery of capabilities. Instead of having a class FlyingAnimal, have a class Animal with a dynamic ...


0

If your function has a lot of out-parameters and if most of the time you only need a subset, then your function does too many things and its “interface” should be simplified. The usual way is functional decomposition / method extraction: break the large function down into smaller ones that do-one-thing-and-do-it-well. Each function would then only ...


2

Core of your problem is, by introducing the asynchronous message queue, your application does not get immediate feedback (like exception messages) any more if db queries start to fail. I see basically two conceptual options for handling this: When the operations put into the message queue fail (like a database write operation), make sure the queue sends ...


9

Keep consistent units within your system, and only convert to the user's preferred format at the boundaries of your system. The “boundary” doesn't necessarily mean front-end or back-end, this is more about how you structure the logic in your application. A classic MVC application would convert incoming data in the controllers, and outgoing data in the views. ...


3

Well, the apply method was designed to create an option from a nullable value, and if you already have an Option, there's not really a need to create one. Also a Some(None) is valid in certain circumstances where you already have an Option and you want to call a method on its contents that also returns an Option, although you would generally use a flatMap ...


0

An effective technique ive used is to create a dict where the keys are the gui elements and their parameters, and the values are the arguments the user put in those parameters. Example data = { frame1:{textBox1:"input text", textBox2:"input text"}, frame2:{Button1: 0, Button2: 1},} If you want to get really slick you can rename the gui elements ...


1

I would recommend drawing a class diagram or a component diagram showing the classes of objects that participate in your sequence diagrams. The messages in your sequence diagrams should match the operations defined on the classes. The relationships among the classes should reflect which classes interact with which other classes. For example, if method X of ...


5

The newfangled Entity-Component-System design says to use option C. Have the system grab all gravity-subject components and gravity-source components and use the position component of the attached entity do the calculation and commit the updated position to the position component. ECS is designed so that Entity's only responsibility is to collect components....


1

In addition to @DocBrown's answer. Q: Do you believe this design is bad or not scalable? How would you improve this or, better, what would you substitute this design with? Locating constants in specific classes is not bad per se. Clustering all the constants in the very same class, at the very same level of abstraction could be problematic. 1 I would ...


3

A design is never inherently "good" or "bad" per se, these attributes cannot be applied sensibly without context. A good design is one which makes a program fit to its non-functional requirements in the most simple manner. And sometimes global variables are exactly this: the most simple solution which fits well into the context. So the question you need to ...


0

maybe, but possilby as a last resort. The best solution would be to encapsulate the contract into the type excepted by f... however a type of int > 0 is impossible or difficult to create in a lot of type systems. (you are really getting into the realms of dependent typing to specify this in the type system, though I think Haskell can do it with GADTs) The ...


2

At first glance, the fact that XxxInterface inherits from XxxInterfaceCallback appears strange, until you see that it is done to support the Qt signal/slot mechanism. Other than that, you appear to be using inheritance exactly for what it is intended to be used for: abstracting away which concrete implementation the rest of the application is using. The ...


2

Duck Typing I'm not a PHP expert but in any programming language using attribute bags as objects, there always exist functions to ensure that a given attribute is defined, and how it is defined. Essentially all the basics you need to enforce Duck Typing. Spaghetti Checks This does leads to a distribution of such checks throughout the code base. Which is ...


2

If your program requires that every item has a name, then you should model the item as a class with a name property, instead of using an array. Then you can change the Register interface so that it is clear that it returns an Item (which has a name) and not just any random type. class Item { public $name; // other properties } class Register { ...


0

I agree that adding criteria1 and criteria2 to BaseFamilyObject.GetCompatibleDevices whether it needs them or not is not a very good idea. If I understand correctly criteria1 and criteria2 do some kind of filtering on the devices that are to be returned by GetCompatibleDevices. Perhaps it's not actually the responsibility of BaseFamilyObject or its ...


0

You decide: Is setting the property to nil allowed and how is the behaviour defined? Or is it disallowed and should throw an exception? Or is it a programming error that should immediately assert? If it’s normal then handle it reasonably. Ignoring it is not reasonable in my opinion. I’d expect the setter to return what the last setter set (usually). ...


3

The moment you wrote bool criteria1, alarm bells should have started ringing in your head: you have a boolean parameter/ flag argument being added to your code. This is a strong code smell and likely indicates that something is going wrong. When you considered bool criteria2 those alarm bells should have started screaming. In reality, this new class wants ...


2

To add to what @deamon said do your vertical slices all the way to the database, don't use referential integrity, use Guids as primary keys, use fields and not entities... Maybe this can help: https://www.youtube.com/watch?v=-4s7ioADuCA https://www.youtube.com/watch?v=yxjrObdWQow Hope this helps :-)


0

I get where you're coming from, I've made many such designs myself, and if that what is expected of you, then of course, it is what you supposed to do. However, I would not design a real system that way. There are a couple of problems with this, the biggest one being, that you just take the "demands" from the user/owner and convert it to a relational data ...


1

The method used is the one most appropriate for the task at hand. To put some of this into perspective, I recognize both map and flatmap as well-known, well-understood functional programming mechanisms for operating on collections, even though I'm not a functional programming expert. Chaining makes sense in this context. In C#, these concepts are used in ...


0

Direct connection of the end user part to the database part is not the recommendable way, because if you allow such a connection: you must expose the database to the outside world, with the risk of admin account being hijacked. you will allow the user to connect with other tools than your app, like for example with an SQL engine hence you have to protect ...


0

Variation on the "do both" theme: Return error codes from your API and provide an additional API for error code translations. This service could handle localization, and by keeping business specific messages on the server you avoid having to update the client when new messages are defined to handle new rules.


2

My advice: do both. :) The API client can decide to use the messages from your API or read each error code and create his own messages. Like: { "errorCode": "4005", "message": "Person already registered" } But if you need to choose one, I would choose the error code solution. The reason: if your API client needs to show another message instead ...


8

If F and G are functions of a class, then you can put validations on public method which can be called from outside. If G is a function which performs its business standalone and F doesn't care whether x > 0 or x <= 0, then you can put this assertion on G and doesn't require to check on F. If F and G are totally different layer functions and F should ...


0

If it never makes any sense for F(x) to receive a negative x, you should assert in F(x) that x is strictly positive. On the other hand, if within F(x) having x being negative or null can make sense you should "only" add some logic to F(x) preventing it from calling G(x) with an invalid x.


Top 50 recent answers are included