object's interface

Source: Internet
Author: User

Aristotle is perhaps the first person to study the concept of "type" seriously, and he has talked about "fish and birds". In the world's first object-oriented language Simula-67, this concept has been used for the time being:
All objects-albeit distinct-are part of a series of objects that have common characteristics and behavior. In Simula-67, the first class keyword was used, which introduced a completely new type for the program (Clas and type are generally interchangeable; annotation ③).

③: Some people make further distinctions, emphasizing that "type" determines the interface, and that "class" is a special implementation of that interface. The

Simula is a good example. As the name implies, its role is to "simulate" (simulate) a classic question like "bank teller". In this example, we have a series of tellers, customers, accounts, and transactions. Each type of member (element) has some common characteristics: each account has a certain amount of balance, each cashier can receive the customer's deposit; At the same time, each member has its own status; Each account has a different balance; each cashier has a name. So in computer programs, you can use unique entities to represent tellers, customers, accounts, and transactions. This entity is "object", and each object is subordinate to a particular "class", which has its own common characteristics and behavior.
Therefore, in object-oriented programming, although what we really want to do is create a wide variety of data "types", almost all object-oriented programming languages use the "class" keyword. When you see the word "type", Think of "class" at the same time, and vice versa.
When you build a class, you can generate many objects based on the situation. Those objects can then be processed as elements that exist in the problem to be resolved. In fact, when we do object-oriented programming, the biggest challenge is to establish an ideal "one-to-one" correspondence or mapping between the elements of the "Problem Space" (where the problem actually exists) and the elements of the "solution Space" (where the actual problem is modeled, such as the computer).
How do you use objects to accomplish really useful work? There has to be a way to make a request to an object to do something practical, such as completing a transaction, drawing something on the screen, or turning on a switch. Each object can only accept a specific request. The request we make to the object is defined by its "interface" (Interface), and the object's "type" or "class" prescribes its interface form. The equivalence or correspondence between "type" and "interface" is the foundation of object-oriented programming.
Let's take the light bulb for example:

Light lt = new Light ();
Lt.on ();

In this example, the name of the type/class is light, and the requests that can be made to the light object include opening (on), closing (off), becoming brighter (brighten), or becoming dimmer (dim). By simply declaring a name (LT), we created a "handle" for the light object. The new keyword is then used to create an object of type light. and assigns it to the handle with an equal sign. To send a message to an object, we list the handle name (LT) and concatenate it with the message name (on) with a period symbol (.). As you can see, the code we use in the program is very simple and intuitive with some predefined classes.

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.