Atitit. Programming language Principle---method overload implementation and design call method principle

Source: Internet
Author: User
Tags php class

Atitit. programming language Principles --- implementation of method overloading and principle of design call method

1 .  overloads include: overloading of common methods and overloading of construction methods 1

1 . 1. horizontal Reload and vertical reload 1

1 . 2. The method signature consists of the method name, number of parameters, parameter type + return type parameter order (named parameter). 1

1 . 3. Reload (reload option) process, as shown in 2

vs   optional parameters law   optional parameters 3

2 . 1. the __call () function is The default magic function of the PHP class 3

2 . 2. Java method overload execution by reflection call method 4

2 . 3. overloads of C + + 4

3 .  Reference 4

1.overloads include: overloading of common methods and overloading of construction methods

The so-called overload is repeated use. This repetition does not use the same thing over and over again, but only the same name. According to this name, depending on the needs of different features provided. This is the overload. To say an example, the word "Father" is actually overloaded. If you call your father, it refers to your father, and if someone calls him father, it is someone else's father. This is also an overload. Depending on the person being called, the object calling this name is not the same, the meaning is different, which is overloaded. So, here is the concept of overloading in the generalized sense.

1.1.horizontal Reload and vertical reload

Clear the intrinsic analysis of overloading, and then take a look at the concept of "transverse overloading" and "longitudinal overloading". A function feature is a version of a function that is implemented in a class, which is equivalent to tiling multiple forms in a class, so it can be understood as a horizontal (tiled) way. The form of virtual function, through inheritance, constitutes a vertical relationship. For example, the father and the son, belong to two generations, is a vertical transfer relationship, the father in the upper layer, the son on the next layer. That is, a longitudinal direction. Virtual functions are supported in C + +, which provides the ability to overload virtual functions, so that's what we call "vertical overloading."

1.2.The method signature consists of the method name, number of parameters, parameter type + return type parameter order (named parameter).

1.3.Reload (reload option)process, as shown in

First get the method name, look for the symbol table, no run out ex

Judging by the number of parameters

Judging by parameter type (strongly typed language)

If (Nomather ()) ex

If (matchcount>1) ex cant select amigo

author:: Nickname:Old Wow's claws( Full Name::AttilaxAkbar Al Rapanui Attilaksachanui) Kanji Name:Ayron, email:[email protected]

Reprint please indicate source: http://www.cnblogs.com/attilax/

2.implementation of overloading::argus parameter vs default value. Optional ParametersMethodOptional Parameters

Php through Func_num_args (); JS via argus parameter

P Ython through Default Value


A language choice overload or an optional parameter is just one of the two. Like C # 4, which supports both forms, is more likely to be confusing.

Copyright belongs to the author.

Python's parameter settings are also sufficient to cope with most of the needs, so the community on the consideration of efficiency and language complexity , we simply don't support function overloading.

2.1.the __call () function is The default magic function of the PHP class

,__call () in the context of an object, if the calling method does not exist, it will be triggered:
<?php
class Methodtest {
Public function __call ($name, $arguments) {
//Note:value of $name is case sensitive.
echo "Calling object method ' $name '"
. Implode (', ', $arguments). "\ n";
     }
}

2.2.Java method overload execution by reflection call method

Paip. the principle of overloading implementation of programming language methods and Python,php,js implementing method overloads in -Attilax 's Column -  Blog Channel -CSDN.NET.htm

2.3. overloads of C + +

In C language, the function symbol name and corresponding function name are the same, and C + + in order to support function overloading, the symbol name is adapted to the corresponding function name. As shown, the function name is func, and the corresponding symbol name is _Z4FUNCV.

In fact, the compiler symbol of a function is related to the function name, the parameter table of the function (including the parameter type and quantity). and different compiler naming rules are not the same. As long as you can guarantee that the same function name and the different function parameter list generate the symbol name is not the same.

3.Reference

Php-php overloads and Polymorphic implementations? - Ask a question about programming social questions . htm

How Java implements overloading a method - Cheng's personal space - Open source Chinese community . htm

C + + overloading: Transverse overloading (static overloading) and vertical overloading (dynamic overloading)-c++ language - programming language -c++ Technology Network . htm

Why does Python not support function overloading? - programming languages - know . htm

Atitit. Programming language Principles---method overloading implementation and principle of design   invocation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.