This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes General Computing and the fly likes Relax a requirement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Relax a requirement" Watch "Relax a requirement" New topic
Author

Relax a requirement

kat hok
Greenhorn

Joined: Oct 10, 2013
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

Joined: Sep 16, 2013
Posts: 47
    
    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

Joined: Aug 16, 2005
Posts: 13868
    
  10

"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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Oct 10, 2013
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

Joined: Jul 11, 2012
Posts: 8

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

Joined: Oct 10, 2013
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

Joined: Jan 28, 2003
Posts: 3932
    
  17

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.


Steve
kat hok
Greenhorn

Joined: Oct 10, 2013
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

Joined: Jan 28, 2003
Posts: 3932
    
  17

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

Joined: Oct 13, 2005
Posts: 36453
    
  15
If we start talking about research languages, then we are well out of “beginners'” territory, so I shall move this discussion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relax a requirement
 
Similar Threads
Overload class methods
BETA: Method resolving, un/boxing varargs mock question
Garbage Collection
Problem in Generic Method Declaration
Symmetric multiple dispatch, binary methods