notaphplover/catan-heroes

Modify method getProbabilityDistribution at src/com/ucm/dasi/catan/game/generator/CatanGenerator.java

abvg9 opened this issue · 8 comments

abvg9 commented

Maybe you could do this differently. Whenever this function is called, a new map is created unnecessarily.

@abvg9 src/com/ucm/dasi/catan/game/generator/CatanGenerator.java is too long to be part of the title. You could use the description to write a more detailed reference. For example:

Title: Modify method getProbabilityDistribution at CatanGenerator.
Description: src/com/ucm/dasi/catan/game/generator/CatanGenerator.getProbabilityDistribution creates a new map whenever is called. Maybe we could perform a different approach in order to reuse the map.

@abvg9 Mhmm the performance impact of this change is minimun but it's true we can do a better job.

What do you propose? A new map is created in order to avoid entry updates. Maybe we could create a wrapper class of a Map in order to guarantee no one can modify the map.

abvg9 commented

@abvg9 Mhmm the performance impact of this change is minimun but it's true we can do a better job.

What do you propose? A new map is created in order to avoid entry updates. Maybe we could create a wrapper class of a Map in order to guarantee no one can modify the map.

I think it's a valid solution, although personally I think that creating a specific wraper just for this class is a bit excessive. Perhaps creating an inaccessible attribute or an intermediate solution would be more proportionate.

@abvg9 Mhmm the performance impact of this change is minimun but it's true we can do a better job.
What do you propose? A new map is created in order to avoid entry updates. Maybe we could create a wrapper class of a Map in order to guarantee no one can modify the map.

I think it's a valid solution, although personally I think that creating a specific wraper just for this class is a bit excessive. Perhaps creating an inaccessible attribute or an intermediate solution would be more proportionate.

@abvg9 Please propose an specific solution, how would you achieve that?

abvg9 commented

As i said, maybe you can create an attribute inside the class.

Which would be the attribute's type? Could you write a code sample?

abvg9 commented

Here you have an example to create a Unmodifiable or Immutable maps. Based on the article, I think it would be best to use a attribute of immutable type.

It's against Interface segregation principle and against Liskov substitution principle.

We can not go with a fake interface implementation (the put method would throw an exception and wouldn't be used).