Skip to content
March 14, 2013 / Danii Oliver

Overloading – Object Oriented Analysis and Design

Overloading

Signature of a method is the name of the method plus the order and type of the arguments.

  • return type is not a signature.
  • with signatures the name of the arg fields is not important it is the type and order.
  • overloading is just reusing the name and changing the args for a unique signature.
  • order and type have to be different
  • does not take return type into consideration. If the return types are different… you will get a compiler error

Class A {
//methods
public void foo(int a){…}

public void foo(char b){…}

public void foo(int a, char b){…}

public void foo(char b, int a){…}

public void foo(string b, string a){…}
}

This is syntactical sugar! It doesn’t improve anything about the program all it does is allow the programmer to not have to remember another method name, all they have to do is set the arguments she wants to set.

*Overloading can only happen inside a class. Feature point the order and type of the arguments must differ for each method.

Have to be in place :

  • must be within one class
  • keep name change order and type of arguments
  • has nothing to do with return types

“Superclass Methods” can be overloaded within a Subclass

Class Printer {
//methods
public string print(int x){…}
}

Class Laser : Printer{
//methods
→ STILL HAS ← public string print(int x){…}
public string print(char y){…}
}

++Overloading and Overloading are NOT related

+++This is not possible in AS3.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: