0

I just want to improve this design, share your thoughts.

enter image description here

Q1. I have specialized Splitter class based on monetary unit as "MonetarySplitter" and "NonMonetarySplitter". Whether doing so is correct? To check inheritance, I used to do "is a" check. It doesn't sounds good for me that "MonetarySplitter" is a "Splitter".

Q2. I have specialized "MonetarySplitter" class in to "EqualMonetarySplitter" and "PercentageMonetarySplitter". Even this doesn't sounds good for me because "EqualMonetarySplitter" and "PercentageMonetarySplitter" class will be for "NonMonetarySplitter" specialization too.

Q3. Any other design parameters need to be considered for Bill splitter application?

  • 4
    Please elaborate on the requirements. I have no idea what a non-monetary bill splitter is (bills are a very money-oriented concept). Judging from what I know about bill splitters from my restaurant experience, your Diagram misses the point completely. The goal of OO design is not to follow as many rules or patterns as possible; the goal is to find a solution that represents your business model in such a way, that you have an easy time implementing the requirements. If it violates rules, that may be ok. And if it happens to follow some patterns it's easier to talk and reason about. – marstato May 20 '18 at 6:55
2

I think using attributes here more logical instead of inheretance. So you may have two attributes here, one for isMonitory and one for isEqual. The based on their value you conditionally execute related logic. Unless there are other reason for the inheretance. This makes code easier to understand and maintain.

  • How split function will be in your case? Whether it will be like monetarySplit(), NonMonetarySplit(), EqualSplit(). Does it make maintanable code? – VINOTH ENERGETIC May 20 '18 at 6:27
  • Split will have if statement that check the value of attributes and execute the needful according to that. If it is required to make the behavior dynamically changeable, as in changing the application behavior based on user selection, then create interface "ISpliter" and implement it as much as different behaviors exists. – Omar May 20 '18 at 10:32
  • Logical cohesion ("the activity or activities to be executed are selected from outside the module") is not good. See cs.unc.edu/~stotts/COMP145/cohesion.html or pages.cpsc.ucalgary.ca/~eberly/Courses/CPSC333/Lectures/Design/… – Jim L. May 29 '18 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.