Answer 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 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 ArticleComment by Filip Milovanović on Modeling invariants that requires data from...
@Basilevs - The idea is to design aggregates so that they reflect the domain, and support the usage patterns in that domain (like, taking into consideration what commonly needs concurrent access by...
View ArticleComment by Filip Milovanović on Modeling invariants that requires data from...
This perspective might be helpful: in the end, it's all just a bunch of objects and functions that are termed differently depending on their role in this particular modeling paradigm. Value - a simple...
View ArticleComment by Filip Milovanović on Should code reviewers reproduce the...
And when QA returns faulty code, how does this boss imagine the fixes happen? Magic? God knows what they think "reproduce the problem" mean - they might be objecting to something that only exists in...
View ArticleComment by Filip Milovanović on Repository and Service Interfaces in an...
@SamuelObisesan Thank you for taking the time to improve the answer. I've accepted most of your edits, but I elected to rephrase some parts of the answer for clarity. There was one edit that didn't...
View ArticleComment by Filip Milovanović on Why is a test coverage type called "code...
Seems like the source of the confusion is simply a quirk of the language: "X coverage" doesn't have to imply "coverage (of something) by X", it can also mean "coverage of X (by something)". In either...
View ArticleComment by Filip Milovanović on Code reusability/inheritance introduces...
Declare those internals as separate classes. You can then either inherit them or compose them into your object. Then write tests for those classes once (if you're using inheritance and the base class...
View ArticleComment by Filip Milovanović on Do I need to create an interface for every...
"which I think means I should create an interface for each service" - it does not mean that. The first point to keep in mind is: this shouldn't be done mechanistically - you actually have to think...
View Article