is java hashcode and equals example of strategy pattern -


if hashmap point of view variable step calculation of hashcode , equals. using hashcode , equals methods hashmap can vary algorithm implement hashing. can't vary strategy calculate hashcode , euals objects of given type t. based on above argument think doesn't fit definition of strategy pattern.

am correct?

the way it's implemented not strategy pattern. if looked more like:

class hashmap {     private final hashingstrategy strategy;      private int computehash(object) {        return strategy.hash(object);     } } 

then strategy pattern. instead, it's more like:

class hashmap {     private int computehash(object) {         return object.hashcode();     } } 

to hashcode of object, hashmap asks object hashcode, doesn't decide how compute it. strategy pattern when can plug in various algorithms particular step, more delegating responsibility object.


Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

java - Jtable duplicate Rows -

java - Run a .jar on Heroku -