Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which pattern to use for this simple problem?

 
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We need to distribute x amount of dollars evenly between 4 people. When you change the share of one person, the rest of the total share gets distributed evenly among the other people.

Simply put, it could be implemented like this:
4 sliders. Change the value of any slider and the rest of the sliders automatically gets the remainder of the amount distributed evenly.

Here are a few examples of that:

person 1: 70%
person 2: 10%
person 3: 10%
person 4: 10%

person 1: 50%
person 2: 30%
person 3: 10%
person 4: 10%

I was thinking of using the Observer pattern for this but I'm not sure because each dependent seems to be a subject.
 
Sheriff
Posts: 17652
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anything, I would think Visitor. That said, I wouldn't even go to patterns right away but first try to see if there is a simple, straightforward way to solve this. Only if it gets complicated or if my solution looks like it fits a pattern would I see if there is anything that following the pattern can do to improve the design.
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic