Strategy Design Pattern and Factory Method Design Pattern
By : user2861096
Date : March 29 2020, 07:55 AM
this one helps. Strategy is about behavior. Factory is about creation/instatation. Suppose you have an algorithm, to calculate a discount percentage. You can have 2 implementations of that algorithm; one for regular customers, and one for extra-ordinary good customers.
|
Strategy Design Pattern (with argument method) - JAVA
By : Julie B
Date : March 29 2020, 07:55 AM
Does that help I'm writing an algorithm which works on a bit serie and do some operations such as shift, AND with it. I wanted to test the algorithm with two different data structure : MutableBigInteger and BitString ( javabdd ), so I thought I'll try to come up with some smart design pattern (since i dont do that a lot) , and I found the strategy design pattern pretty interesting. The only thing that bothers me is that for the function AND, it needs the same type to be computed. I explain with some code : , Don't think this is the cleanest way, but you could use generics: code :
public interface BitTrain<T extends BitTrain<?>> {
public void shift();
public void and(T b2);
}
public class MutableBigInteger implements BitTrain<MutableBigInteger> {
public void shift();
public void and(MutableBigInteger b2){
// ...
}
}
|
Does my example for using the Strategy design pattern with the Template Method design pattern make sense?
By : Shivam Rathore
Date : March 29 2020, 07:55 AM
around this issue As Per my Understanding your example does't fit into the Strategy and Template, the Scenario best fits into Abstract Factory and May be Prototype (Depends upon full requirement). The basic difference between strategy and Template is Inheritance v/s Delegation. If you are Searching for Strategy and template Example i would suggest you to go with some game application where the Full game can fit into template function like end of game, start the game,Winner of the game looser of the game and the Rules to play the can be fitted into Strategy like when to move, what to do with some moves.
|
JAVA - extends vs interface - Strategy design pattern
By : user3336749
Date : March 29 2020, 07:55 AM
hop of those help? Strategy design pattern will help you. Well One thing that you should kept in mind.
|
I am trying to implement the strategy design pattern in the below snippet using Java 8 .Looking for better ways to imple
By : Ivano
Date : October 01 2020, 05:00 AM
will help you Strategies should implement the abstraction needed by the service. In this case, the service needs a Function so then a strategy would be... code :
class ReclinerTicketStrategy implements Function<Integer,Double> {
@Override
public Double apply(Integer noOfTickets) {
return noOfTickets * 200.0;
}
}
|