33 votes
Accepted

How to comprehend abstraction in code?

Programming concretely is the impulse to pull details towards you so you can nail them all down in one place. We all start this way and it's hard to let go. Programming abstractly is most definitely &...
candied_orange's user avatar
22 votes
Accepted

Advantages of Strategy Pattern

For one thing, big clumps of if/else blocks are not easily testable. Each new "branch" adds another execution path and thus increases the cyclomatic complexity. If you want to test your code ...
scriptin's user avatar
  • 4,432
21 votes
Accepted

What do I use as an alternative to Domain-Driven Design, if I cannot define a Competitive-Advantage area of my system to apply it?

Here are some rules that I have come up with to help: The Rule of Requisition: Use a tool/technique/principle only when the benefits exceed the costs.* Note that "competitive advantage" is ...
Robert Harvey's user avatar
13 votes

How to comprehend abstraction in code?

At the bottom, there are some updates to how this fared for me every quarter of the year or so, I think they're valuable. Good naming. Or, if it's someone else's code, trying to attribute good names /...
coolpasta's user avatar
  • 641
12 votes

Disadvantage of the strategy pattern and how to overcome it

This quote is surprising and misleading. Design patterns are not chosen in a catalogue by comparing pros and cons! Patterns are chosen because they address a very specific problem that you are facing....
Christophe's user avatar
  • 74.7k
10 votes
Accepted

Rich domain model vs strategy pattern in DDD

The logic was supposed to be implemented inside the entities Yes, although it's usually more specific than that - the logic that computes the new state of an entity is supposed to be "inside" the ...
VoiceOfUnreason's user avatar
8 votes

Implementing strategy pattern multiple variables?

The intent of the strategy pattern according to the GoF is to "define a family of algorithms, encapsulate them and make them interchangeable. The strategy lets algorithms vay independently from ...
Christophe's user avatar
  • 74.7k
7 votes

The "real and effective" GIT CI/CD strategy

By having three repo you kind of have a branching strategy already but a complex one. I think you're not facing a technical issue but a cultural issue. Even if your solution is good (I think it is but ...
JayZ's user avatar
  • 827
6 votes
Accepted

Strategy pattern and "Is a" relationship

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 ...
Bart van Ingen Schenau's user avatar
6 votes

What do I use as an alternative to Domain-Driven Design, if I cannot define a Competitive-Advantage area of my system to apply it?

In the Red book (implementing DDD), there is DDD scorecard at page 11, which helps you recognize when DDD should be considered. for example If your project contains 30+ user stories will grow in ...
Muflix's user avatar
  • 195
5 votes

Liskov substitution and abstract classes / strategy pattern

TL;DR: Different subtype constructors are not only ok, they are expected. Liskov directly addresses the usage of different constructors in her paper Behavioral Subtyping Using Invariants and ...
dietbuddha's user avatar
  • 8,687
5 votes

Advantages of Strategy Pattern

Strategy is useful when the if/then conditions are based on types, as explained in http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html Type-checking conditionals usually don't ...
Fuhrmanator's user avatar
  • 1,435
5 votes

Advantages of Strategy Pattern

Why is it beneficial to use the strategy pattern if you can just write your code in if/then cases? Sometimes you should just use if/then. It is simple code that is easy to read. The two key problems ...
Telastyn's user avatar
  • 109k
5 votes
Accepted

Looking for a strategy to ensure name of child node stays unique in collection

Uniqueness of those names is a property which is clearly defined only in context of a Pages collection. That is most easiest understood when you think of a Page object changing its "parent" container, ...
Doc Brown's user avatar
  • 200k
5 votes

Rich domain model vs strategy pattern in DDD

In rich domain model we are supposed to put domain logic into entities The problem with this sentence is, people interpret it wrong as "we are supposed to put all domain logic into entities". A ...
Doc Brown's user avatar
  • 200k
5 votes

Rich domain model vs strategy pattern in DDD

I see Employer as the aggregate root here. When you do OO modeling, usually a business function is defined on the subject of the action, not the initiator of the action. It depends on the ...
Robert Bräutigam's user avatar
4 votes
Accepted

Zero Downtime Deployment - Transitional Db Schema

It sounds like what you are really looking for is not so much High Availability as you would need Continuous Availability. Essentially your plan will work but you seem to have noticed that the major ...
maple_shaft's user avatar
  • 26.4k
4 votes
Accepted

When can client code know about strategy pattern implementations?

I looks to me that you have two different problems. Problem A is easy to solve. But problem B is harder. Problem A is to dynamically call a given strategy given a configString. That can be solved by ...
Tulains Córdova's user avatar
4 votes

How To: .Net periodic task to validate entries in tables

Write a program that queries the DB and does the things it needs to do. Run it as a scheduled task using the tools provided by the target operating system. Job done. Don't write your own scheduler. ...
LoztInSpace's user avatar
  • 1,149
4 votes

Internal REST API versioning strategy

You should have a versioning strategy because that is key to independent evolvability, but it should be tied to Content-Type, not URLs or anything else. Even in a closed-house setting, you should ...
Nicholas Shanks's user avatar
4 votes
Accepted

Reconciling MVC with a strategy pattern

The MVC design pattern does not specify the mechanics involved in choosing which view to render. Both ways are "MVC". If you are rendering a collection of books, the controller renders a single view ...
Greg Burghardt's user avatar
4 votes

Discount calculation pattern

The intent of the Strategy pattern is to encapsulate a family of algorithms and use them interchangeably. But your current need seems to be very different: You want to apply different algorithms ...
Christophe's user avatar
  • 74.7k
4 votes

Strategy & Architectural Decision: Customer data migration between two companies

Great, more email for the spam folder... OK seriously now: your business' desire to merge the user accounts is not of concern for the customer. Therefore, the customer will not have any desire for ...
mtj's user avatar
  • 1,914
4 votes
Accepted

How to implement Gang of Four's Lexi's Compositor-Composition?

The idea behind Lexi's Composition/Compositor combination is that an empty document starts with a Composition without children and a concrete Compositor that determines how the formatting of the ...
Bart van Ingen Schenau's user avatar
3 votes
Accepted

Strategy Pattern with abstract class instead of interface?

Is the strategy in the strategy pattern always an interface? That depends on what you mean by "interface". If you mean the standard general programming meaning of "an abstraction that hides its ...
Jörg W Mittag's user avatar
3 votes

Advantages of Strategy Pattern

[...] if you can just write your code in if/then cases? That is exactly the greatest benefit of strategic pattern. Not having conditions. You want your classes/methods/functions to be as simple and ...
Andy's user avatar
  • 10.2k
3 votes

Why do we need a context class in strategy pattern?

In some languages, notably C# and Java, you can strategize, not the sorting algorithm, but the way the objects being sorted are compared for ordering purposes. For example, in C#, you could say ...
Robert Harvey's user avatar
2 votes

Advantages of Strategy Pattern

There is nothing wrong with if/else per se. In many cases if/else is the simplest and most readable way of expressing logic. So the approach you describe is perfectly valid in many cases. (It is also ...
JacquesB's user avatar
  • 57.4k
2 votes

Advantages of Strategy Pattern

Why is it beneficial to use the strategy pattern if you can just write your code in if/then cases? The Strategy Pattern lets you separate your algorithms (the details) from you business logic (high ...
Alain O'Dea's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible