Mapping Methods With Arguments in Object-Oriented Programming

Mapping Methods With Arguments in Object-Oriented Programming
Slide Note
Embed
Share

This slidedeck delves into how calling a method with another object as input impacts the properties of objects in a class. Using the Dillo class and its longerThan method as an example, it illustrates how areas under the hood get modified. The presentation demonstrates the process step by step with visual aids, highlighting the changes in object properties before and after method calls.

  • Object-oriented programming
  • Methods
  • Input arguments
  • Under the hood
  • Dillo class

Uploaded on Apr 30, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Mapping Methods With Arguments This slidedeck shows how the areas of our under the hood map get modified when you call a method that takes another object as input. We again use the Dillo class, but this time after we have written a longerThan method (that takes another Dillo as input).

  2. KNOWN CLASSES OBJECTS class Dillo { int length; boolean isDead; Dillo: length = 8; isDead = false; boolean longerThan(Dillo other) { return (this.length > other.length); } Dillo (int length, boolean isDead) { this.length = length; this.isDead = isDead; } Dillo: length = 24; isDead = true boolean longerThan(Dillo other) { return (this.length > other.length); } boolean longerThan(Dillo other) { return (this.length > other.length); } } We start with two objects bound to the names babyDillo and adultDillo. Notice that each object contains a copy of the method NAMED VALUES EXPRESSION (impact on other areas are in red) babyDillo adultDillo

  3. KNOWN CLASSES OBJECTS class Dillo { int length; boolean isDead; Dillo: length = 8; isDead = false; boolean longerThan(Dillo other) { return (this.length > other.length); } Dillo (int length, boolean isDead) { this.length = length; this.isDead = isDead; } Dillo: length = 24; isDead = true boolean longerThan(Dillo other) { return (this.length > other.length); } boolean longerThan(Dillo other) { return (this.length > other.length); } } Now we call the longerThan method on adultDillo, passing babyDillo as the argument The name this now refers to adultDillo, and other refers to babyDillo NAMED VALUES EXPRESSION (impact on other areas are in red) babyDillo adultDillo adultDillo.longerThan(babyDillo) this other

  4. KNOWN CLASSES OBJECTS class Dillo { int length; boolean isDead; Dillo: length = 8; isDead = false; boolean longerThan(Dillo other) { return (this.length > other.length); } Dillo (int length, boolean isDead) { this.length = length; this.isDead = isDead; } Dillo: length = 24; isDead = true boolean longerThan(Dillo other) { return (this.length > other.length); } boolean longerThan(Dillo other) { return (this.length > other.length); } } The expression being evaluated now changes to the body of the method from the adultDillo class NAMED VALUES EXPRESSION (impact on other areas are in red) babyDillo adultDillo this.length > other.length this other

  5. KNOWN CLASSES OBJECTS class Dillo { int length; boolean isDead; Dillo: length = 8; isDead = false; boolean longerThan(Dillo other) { return (this.length > other.length); } Dillo (int length, boolean isDead) { this.length = length; this.isDead = isDead; } Dillo: length = 24; isDead = true boolean longerThan(Dillo other) { return (this.length > other.length); } boolean longerThan(Dillo other) { return (this.length > other.length); } } To evaluate this expression, follow the arrows from the names: this refers to the lower object, which has length 24, while other refers to the upper object Substitute these values in the expression NAMED VALUES EXPRESSION (impact on other areas are in red) babyDillo adultDillo 24 > 8 this other

  6. KNOWN CLASSES OBJECTS class Dillo { int length; boolean isDead; Dillo: length = 8; isDead = false; boolean longerThan(Dillo other) { return (this.length > other.length); } Dillo (int length, boolean isDead) { this.length = length; this.isDead = isDead; } Dillo: length = 24; isDead = true boolean longerThan(Dillo other) { return (this.length > other.length); } boolean longerThan(Dillo other) { return (this.length > other.length); } } Next we execute the return, which ends the method. The this and other names go away (they are only active while the method is being evaluated) NAMED VALUES EXPRESSION (impact on other areas are in red) babyDillo adultDillo return true

  7. KNOWN CLASSES OBJECTS class Dillo { int length; boolean isDead; Dillo: length = 8; isDead = false; boolean longerThan(Dillo other) { return (this.length > other.length); } Dillo (int length, boolean isDead) { this.length = length; this.isDead = isDead; } Dillo: length = 24; isDead = true boolean longerThan(Dillo other) { return (this.length > other.length); } boolean longerThan(Dillo other) { return (this.length > other.length); } } This example illustrates how names (this and parameters) are added to the map when calling a method, then removed when a method is finished NAMED VALUES EXPRESSION (impact on other areas are in red) babyDillo adultDillo

More Related Content