Java programming ideas [1]

Alan Kay summarized the five basic characteristics of Smalltalk. This is the first successful object-oriented programming language and the basic
language of Java . Through these characteristics, we can understand what a "pure" object-oriented programming method is like:
(1) Everything is an object. Think of an object as a new type of variable; it holds data, but it can be required to operate on itself. In theory
, all conceptual components can be proposed from the problem to be solved, and then expressed as an object in the program.
(2) A program is a combination of a large number of objects; through message passing, each object knows what to do. In order to make a request to
an object, "send a message" to that object. More specifically, you can think of a message as a call request, which calls a
subroutine or function belonging to the target object .
(3) Each object has its own storage space, which can accommodate other objects. In other words, by encapsulating existing objects, new types of objects can be created. Therefore
, although the concept of objects is very simple, they can reach arbitrarily high levels of complexity in programs.
(4) Every object has a type. According to the grammar, every object is an "instance" of a "class". Among them, "Class" (Class)
is a synonym for "Type". The most important feature of a class is "what message can be sent to it?".
(5) All objects of the same type can receive the same message. This is actually a statement with a different meaning, and everyone will soon be able to understand it. Since
an object of type "Circle" also belongs to an object of type "Shape", a circle can completely receive shape
information. This means that the program code can command the "shape" uniformly, so that it can automatically control all objects that conform to the description of the "shape", which naturally includes the
"circle". This feature is called the "substitutability" of objects and is one of the most important concepts of OOP.

"Class creator" (the person who creates the new data type) and the "customer programmer" (
the person who uses the ready-made data type in their own application ; note ④). For customer programmers, the main goal is to collect a programming "toolbox
" full of various types in order to quickly develop applications that meet their requirements. For class creators, their goal is to build a class from scratch,
opening only the necessary things (interfaces) to the client programmers, and all other details are hidden.

"Interface" (Interface) specifies which requests can be made to a particular object.
private creates a wall between you and the client programmer.
"Protected" (protected) is similar to "private", except that an inherited class can access protected members but not private members.

Although the function interface used has not changed, its new version has a different performance

When sending a message to an object, if you don't know the specific type of the other party, but the action taken is also correct, this situation is called
"polymorphism". For object-oriented programming languages, the method they use to achieve polymorphism is called "dynamic
binding".
Abstract basic classes and interfaces.
We don’t want anyone else to actually create an object of the basic class, but only model the uptrack into It in order to use their interface

. The "Exception" here
belongs to a special object that will be "thrown" or "thrown" from the place where the error occurred. This violation will then be caught by
a "violation controller" designed to control specific types of errors.

Guess you like

Origin blog.csdn.net/weixin_42462804/article/details/106800199