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 &...
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 ...
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 ...
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 /...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
strategy × 81design-patterns × 43
design × 15
object-oriented × 13
object-oriented-design × 9
java × 5
c++ × 5
algorithms × 4
architecture × 3
android × 3
language-agnostic × 3
patterns-and-practices × 3
versioning × 3
abstract-class × 3
c# × 2
php × 2
database × 2
unit-testing × 2
programming-practices × 2
domain-driven-design × 2
git × 2
mvc × 2
interfaces × 2
inheritance × 2
deployment × 2