# Relax a requirement

kat hok
Greenhorn
Posts: 10
Hi!
What does it mean to relax a requirement? For example in a simple method which takes in two Intergers and adds them together to another Integer, how can one relax a requirement in that method?

Daniel Hirning
Ranch Hand
Posts: 50
1
Hi Kat,

Unsure exactly what relaxing a requirement means.

From the code given, all I can think is it shouldn't take add(x,y) to add two Integers?

Hope that helps til a mod can tell me I'm wrong

cheers,
Daniel

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
"Relax a requirement" usually means to make some requirement about what the method should do or how it should work, less strict.

What exactly is meant in a certain situation, depends on what requirement exactly it is and what about it might be done less strictly.

Given some simple method but without any idea what the requirements for the method are or what might be done less strictly, it's impossible to answer the question in a general way for that simple method.

If you've encountered the phrase "relax a requirement" somewhere and you want to know what is meant in that case, you'll have to explain more about the context of where you found the phrase.

Maneesh Godbole
Saloon Keeper
Posts: 11069
13
Agree with Daniel and Jesper. We need more context.
One possible interpretation could be even if argument is a negative number, treat it as positive.

Campbell Ritchie
Sheriff
Posts: 49382
62
Another interpretation is shown in these two methodsThe first version requires an argument in the range 0…100 and the overridden version relaxes that requirement. It will accept arguments up to 200.

Campbell Ritchie
Sheriff
Posts: 49382
62
Note that strengthening the requirement, which you can do by swapping ONE_HUNDRED and TWO_HUNDRED in my previous post would breach the Liskov Substitution Principle and would mean the subclass method is not a true overriding.

kat hok
Greenhorn
Posts: 10
OK, thanks everyone! Think i got it now. I have another question also, but I have to give you the whole exercise then;

Some research languages have symmetric multiple dispatch - methods are defined outside classes, and dispatch dynamically on all arguments regardless of order (no overloading at all). There is no designated receiver for a method but rather all arguments are of the same priority - this is intended to handle binary methods better which are often naturally symmetric. The runtime selects the most specific method to dispatch according to all arguments, and so there must be a single best implementation for each possible invocation of a method. The return type is not considered in the implementation selection. When compiling a package the compiler analyzes all types used in the package and all methods and makes sure that for each method and argument types combination there is a single best method to be called - or issues an error if that is not the case. Assume the following three classes in such a language

The elipsis in each class body represents (possibly) private data but no other methods.
Each package compiles successfully on its own.
A user has now written the following client:

And my question is:
What would be the problem in allowing this client to compile in a type safe multiple
dispatch language? Show code that would expose the problem.

Wilhelm Vogt
Greenhorn
Posts: 10
You might look up 'multiple implementation inheritance' or 'Diamond Problem'. As I understand the problem, it applies to this question.

kat hok
Greenhorn
Posts: 10
Wilhelm Vogt wrote:You might look up 'multiple implementation inheritance' or 'Diamond Problem'. As I understand the problem, it applies to this question.

Thanks, now I get why it won't work! But I still don't know how to show code to expose the problem. Do you have any thoughts?

Steve Luke
Bartender
Posts: 4181
22
kat hok wrote:Thanks, now I get why it won't work! But I still don't know how to show code to expose the problem. Do you have any thoughts?

Start thinking about what the possible parameters to the method might be. Then consider what versions of add() are available to the client. Then try to find the method that will be called for any combination of parameters. Determine which one add method is best for that particular set of parameters. If you can't explain why one method is better then all the others you found your problem.

kat hok
Greenhorn
Posts: 10
Steve Luke wrote:
kat hok wrote:Thanks, now I get why it won't work! But I still don't know how to show code to expose the problem. Do you have any thoughts?

Start thinking about what the possible parameters to the method might be. Then consider what versions of add() are available to the client. Then try to find the method that will be called for any combination of parameters. Determine which one add method is best for that particular set of parameters. If you can't explain why one method is better then all the others you found your problem.

I've found out that the methods that are available, are the two first add(..) methods in Natural and Even, but it can't be determined which one of them is the best for the call. Therefore as you say, I can't explain why one method is better than all the others. But I still don't know how to show this using code?

Steve Luke
Bartender
Posts: 4181
22
Take the situations available, write them in code, and indicate using comments which ones should show compile problems. To be inclusive, I would also indicate for each line which add() method would be executed when an exception would not occur, and for the combinations that do cause exceptions, indicate which methods would be competing for 'the best' implementation.

Please don't expect anyone to do this for you, that isn't how this forum works.

Campbell Ritchie
Sheriff
Posts: 49382
62
If we start talking about research languages, then we are well out of “beginners'” territory, so I shall move this discussion.