Answer by Filip Milovanović for The notion of configurable strategies
"As you can see above, each Strategy is optionally configurable through its constructor."This is perfectly fine/normal, and is in fact one of the cornerstones that makes polymorphic types flexible: you...
View ArticleAnswer by Filip Milovanović for Should an optional boolean function argument...
I agree that you should go with what makes more sense semantically, but I also find that, when the boolean argument is optional, the thing that fairly often makes more sense when omitting it is for it...
View ArticleAnswer by Filip Milovanović for Is it okay for an Interface Adapter /...
The More General Part of the AnswerI'm going to answer the question you stated in your closing line, but there's a caveat - see below.Is this okay? Considering the Interface-Adapter and Gateway are...
View ArticleAnswer by Filip Milovanović for Which Clean Architecture Areas do Gateways...
Without seeing more code than what you provided in your Typescript example, it's impossible to be 100% certain, but I'd wager that the following is roughly correct (if not, just mentally shift it by...
View ArticleAnswer by Filip Milovanović for Tests of 1-Dependency VS Tests of 0-Dependency
"why are "unit tests" considered so important when they don't reallytest your application"Perhaps an analogy will help; an isolated unit test is like SpaceX engineers testing one of their Raptor...
View ArticleAnswer by Filip Milovanović for How can I achieve polymorphism if MVC logic...
Context: From some of your comments, it seems like you're dealing with what's basically a desktop application running on JavaScript, so this is mostly written in that light (that is, the scenario is...
View ArticleAnswer by Filip Milovanović for What is the relationship between variance,...
"In a general sense, covariance is achieved when the direction ofassignment compatibility is preserved. Contravariance is achieved whenthe direction of assignment compatibility is reversed."You omitted...
View ArticleAnswer by Filip Milovanović for Liskov Substitution Principle Edge Case
A class doesn't violate LSP by merely having an extra method. The behaviors that LSP talks about are not methods, but rules and relationsips and constraints that the class is meant to follow/enforce as...
View ArticleAnswer by Filip Milovanović for In Clean Architecture, how do we name...
Here are a couple of guidelines:1. Don't use the UseCase suffix. UseCase, within Clean Architecture, is more of a role that a piece of code has within the system. While it might be helpful at first to...
View ArticleAnswer by Filip Milovanović for Is this really loosely coupled?
My guess is that the idea here is for client code to use service-specific interfaces (like your IProductService), that decouple them from the service implementations.If so, the intended dependency...
View ArticleAnswer by Filip Milovanović for Unit Testing - should / how should I write...
Regarding call verification - test doubles/mocks that check if a method was called (at all, or with certain parameters, etc.) are called Spies. See this article on different kinds of test doubles...
View ArticleAnswer by Filip Milovanović for ECMAScript Primitives: Immutability vs Value...
"You could just say that primitives are stored directly in a variable.Such a value could never take any effect on other variables"That's not true. This is where the metaphor that describes a variable...
View ArticleAnswer by Filip Milovanović for Should edge cases be part of one test, or...
I'll give you an overview of what tests should look like, but note that it might not be easy to achieve this without having a certain level of experience, and that it may be better to think of this as...
View ArticleAnswer by Filip Milovanović for What is the responsibility of a typed...
Ideally, the models (data structures or proper objects) exposed by the application layer interface, as well as the methods on the interface, would not be defined by the external API specification....
View ArticleAnswer by Filip Milovanović for How do you decompose big object for testing?
What you want to do is test the contract between the two objects.One set of unit tests checks the behavior of the sub-object in isolation. This set of tests is essentially a representation of various...
View ArticleAnswer by Filip Milovanović for Message Dispatching: If, Visitor, or...
I should be able to add new types of messages AND/OR new types of handlers without affecting the existing messages or handlers (i.e., loose coupling).So, what you might be running into here is known in...
View ArticleAnswer by Filip Milovanović for Clean Arch: Where to put HTTP request inputs...
From what i understand of the clean arch., I/Os from the "outside" should be handled by the presentation layer.. but because the presenter has to be called after the service it has no chances to take...
View ArticleAnswer by Filip Milovanović for Visitor Pattern: what's the point of the...
But I really don't see the point of that accept call. If you've got the visitor and the objects to be visited, why not just pass these objects directly to the visitor and avoid the...
View ArticleAnswer by Filip Milovanović for Does the Visitor Pattern necessitate...
I have a class hierarchy of elements (more static) with differentoperations on them in another class hierarchy (more flexible). ... Idecided to use the Double Dispatch technique:elem.do(operationObj) {...
View ArticleAnswer by Filip Milovanović for Why just "interface segregation principle"...
These principles are largely language agnostic, so, the word "interface" doesn't mean a Java interface type (although, that's often what it will end up being in Java). The term is used in its more...
View ArticleAnswer by Filip Milovanović for Will I lose confidence of my code working in...
Now that I've read your question a bit more thoroughly, I think the problem lies in you being unclear about what the public API of the IMagic type is, and how the return value figures in it. (It is not...
View ArticleAnswer by Filip Milovanović for What's the difference between Observer...
This is the Observer pattern - it's the exact same thing.I have used some kind of "listeners" where I have an interface implemented by classes that need to be notified of some event (e.g.:...
View ArticleAnswer by Filip Milovanović for What is the right understanding for cohesion...
Firstly, am I wrong in assuming that just asking about cohesion and coupling with regards to this code is enough to motivate this refactoring, or should I be using other principles, asking other...
View ArticleAnswer by Filip Milovanović for In unit testing: How to abstract a dependency...
Mark Seemann makes a good point, but it's important to not take these things as a universal law, and understand them with more nuance. Your GetMenuList method might be too simple for this to apply, but...
View ArticleAnswer by Filip Milovanović for In "Liskov Substitution Principle", is...
Typical online accounts of LSP are often simplified or handwavy, or lack context, so you have to keep in mind that some of the stuff that you can find out there is not necessarily 100% representative...
View ArticleAnswer by Filip Milovanović for Why is "hidden dependency" (required things...
First some context - these named refactorings (from Refactoring by Martin Fowler) aren't necessarily meant to tell you what's better design-wise, they are just things that you can do to transform your...
View ArticleComment by Filip Milovanović on Why is global state hard to test? Doesn't...
@Steve - I'm not saying this is specific to global state, I'm pointing out to the OP that this is also a possibility, in response to their idea that the problem will be solved by just "writing all the...
View ArticleAnswer by Filip Milovanović for Why the instability metric is a ratio?
Well, no metric is perfect. A metric is a relatively simple way to get a handle on some property of a complicated thing - for instability, think of it as of a normalized/relative metric (a value...
View ArticleComment by Filip Milovanović on Clean Architecture - Chapter 23: Presenters...
@Tozine - "like "Screen About Presenter," which would load the necessary information for the view" - I'm not sure I understand what you mean by that, could you elaborate a bit further? Do you mean...
View ArticleComment by Filip Milovanović on Handling class specific behavior:...
Be aware that your two options (which may also appear in other guises) involve a tradeoff: with polymorphism, the abstract interface gets harder to change the more client and component classes you...
View ArticleComment by Filip Milovanović on Split single repository/service into pieces...
The idea to have a repo per endpoint (or better, per use-case) is fine. In a strongly typed language, you might also do this separation on the interface level, but potentially allow one repo to...
View ArticleComment by Filip Milovanović on Must getters return values as is?
A getter is a part of the public interface of a class. The public interface defines how the class communicates with the outside world, allowing you to change the underlying (internal) representation if...
View ArticleComment by Filip Milovanović on What is "vibe coding" and what are the strong...
According to Wikipedia, it's not really coding, in the sense that one does not actually write any code, but develops an app by hoping an AI will spit out something kind of usable based on a descriptive...
View ArticleComment by Filip Milovanović on how can CQRS improve performence when we have...
It's not necessarily an architecture (or a pattern, however you want to think about it) that's suitable for everything. Think for example, about a scenario where you have different access patterns /...
View ArticleComment by Filip Milovanović on how can CQRS improve performence when we have...
"Have you ever noticed that some kinds of money will show you the face of the current monarch?" - I'm guessing people who don't live in a monarchy aren't likely to notice this, but nice example :D
View ArticleComment by Filip Milovanović on In "disadvantages of global states", what is...
The behavior is not literally unpredictable - if you keep track of all the relevant information. But, that means you'd have to find all the hidden dependencies, and keep track of a myriad of ways these...
View ArticleComment by Filip Milovanović on Is it valid for two small aggregates to have...
You can load database entities partially into different objects or aggregates based on context, and have different behaviors when writing them back. You can also consider relying on the compiler to...
View ArticleComment by Filip Milovanović on Difficulty understanding benefit of...
@Basilevs - that's only if you assume that you need to guess it all up front. It's meant to be the result of an iterative process.
View ArticleAnswer by Filip Milovanović for When is multiple validation layers of...
Trust No OneAn important guideline is to never trust outside input of any kind - because what's coming from outside the application is not really under your control. A web-based frontend may impose...
View Article