Fractions in Study class 1.11

Hello guys…
I’m working in the studio for the class 1.11

I’m reading this case, but I don’t understand what is the logic in the method simplify. I understand a fraction should be able to simplify itself, but in my logic, it should change itself and that is it, why it says that the method should return a new fraction? What is the logic there?

Fraction

A fraction has a numerator and denominator. A fraction should be able to add itself to another fraction, returning a new fraction that represents the sum. A fraction should be able to multiply itself by another fraction, returning a new fraction as the product. A fraction should be able to take the reciprocal of itself, returning that value as a new fraction. A fraction should be able to simplify itself, returning a new fraction as that simplification.

Hi,

This is an interesting question. Before answering, I reviewed my solution and realized that I had implemented mine just as you would, using the logic “it should change itself and that is it”.

Mathematically, both approaches work. But perhaps there is a business logic for NOT destroying the original value.

Reasons for returning a new fraction instead of modifying the original one:

• To learn the difference between mutator/modifier functions and pure functions
• To avoid potential undesirable side-effects (when a value/object is used by two processes and is unexpectedly modified by one of them)
• To demonstrate an ability to understand, follow and meet the technical requirements/specifications (I failed this one, apparently. )

This is a great question, and you should ask it on our class’s Slack. Perhaps the instructor and the TAs have a different take on it. I am curious to hear other opinions about it too.

By the way, in Chapter 13, Topic 4. Arithmetic Methods, the textbook implements the `simplify` method as a mutator (modifying the original fraction). Perhaps they indeed wanted us to see both versions/approaches.