PHP from getting started to expert video tutorials on resource recommendations

Source: Internet
Author: User
In PHP from getting started to mastering video tutorials, PHP (foreign name: Php:hypertext Preprocessor, Chinese name: Hypertext preprocessor) is a common open source scripting language. The grammar absorbs the C language, Java and Perl features, is conducive to learning, widely used, mainly for the field of web development. PHP's unique syntax mixes the syntax of C, Java, Perl, and PHP's own creation. It can execute Dynamic Web pages more quickly than CGI or Perl. Dynamic pages made in PHP are compared to other programming languages, and PHP is executed in HTML (an application under the standard Universal Markup Language), which is much more efficient than CGI, which generates HTML markup entirely; PHP can also execute post-compilation code, Compilation can achieve encryption and optimize code execution, making code run faster.

Course Play Address: http://www.php.cn/course/351.html

The teacher's lecture style:

The lectures are kind and natural, unpretentious, no affectation, nor deliberately rendered, but instilled, careful way, between teachers and students in a kind of equality, cooperation, harmonious atmosphere, the silent emotional exchange, the thirst for knowledge and exploration into a simple, real teaching situation, students in the quiet thinking, To gain knowledge in silent consent

The difficulty in this video is the three main features of object-oriented programming:

First, the package

Encapsulation literally is the meaning of packaging, the professional point is information hiding, refers to the use of abstract data types to encapsulate data and data-based operations together to form an indivisible independent entity, the data is protected in the abstract data type inside, as far as possible to hide the internal details, Only some external interfaces are retained to make them contact external. Other objects of the system can communicate and interact with this encapsulated object only through authorized operations that are wrapped outside the data. This means that the user does not need to know the details inside the object, but can access the object through the interface provided by the object externally.

For encapsulation, an object encapsulates its own properties and methods, so it does not need to rely on other objects to do its own work. There are three major benefits to using encapsulation:

1, good package can reduce the coupling.

2, the structure within the class can be freely modified.

3, the member can be more precise control.

4, hide information, realize the details.

Encapsulation to privatize the properties of an object, while providing some of the methods that can be accessed by the outside world, if you do not want to be outside the method, we do not have to provide methods for external access. But if a class does not provide access to the outside world, then this class is meaningless.

public class Husband {            /      * * Property Encapsulation      * A person's name, gender, age, wife are the private attributes of this person */      private String name;      Private String sex;      private int age;      Private Wife Wife;            /      * Setter (), getter () is the interface developed by the object */public      String getName () {          return name;      }        public void SetName (String name) {          this.name = name;      }        Public String Getsex () {          return sex;      }        public void Setsex (String sex) {          this.sex = sex;      }        public int getage () {          return age;      }        public void Setage (int.) {          this.age = age;      }        public void Setwife (Wife Wife) {          this.wife = Wife;      }  }

Encapsulation allows us to easily modify the internal implementation of a class without modifying the client code that uses the class. You can control the member variables more precisely.

1. public void Setage (int. age) {  2.     if (age >) {  3.         System.out.println ("Error:error age input ....");    Prompt for error message  4.     } else{  5.         This.age = age;  6.     }  7.}
. Public String Getsexname () {  2.         if ("0". Equals (Sex)) {  3.             Sexname = "female";  4.         }  5.         else if ("1". Equals (Sex)) {  6.             Sexname = "male";  7.         }  8.         else{  9.             Sexname = "Shemale";  Ten.         }  .         return sexname;  .     }

Ii. inheritance

2.1 Succession Overview

Inheritance is the technique of building a new class using the definition of an existing class, and the definition of a new class can add new data or new functionality, or it can use the functionality of the parent class, but not selectively inherit the parent class. By using inheritance, we can easily reuse the previous code, which can greatly improve the efficiency of development.

Inheritance describes the "is-a" relationship, if there are two objects A and B, if it can be described as "A is B", it can be said that a inherits B, where B is the successor called the parent class or superclass, A is the successor called the subclass or derived class.

In fact, the successor is the specialization of the successor, in addition to having the characteristics of the successor, but also has its own unique characteristics. For example, cats have the characteristics of catching mice, climbing trees and other animals. At the same time in the inheritance relationship, the successor can be completely replaced by the successor, and vice versa, for example, we can say that cats are animals, but can not say that animals are cats is the truth, in fact, we call it "upward transformation."

Admittedly, inheritance defines how classes relate to each other and share attributes. For several of the same or known classes, we can abstract out their common behavior or zodiac and define them as a parent class or superclass, and then inherit the parent class with these classes, and they can not only own the properties of the parent class, methods, but also define their own unique properties or methods.

At the same time, you need to remember three words when using inheritance:

1. Subclasses have properties and methods that are not private to the parent class.

2, subclasses can have their own properties and methods, that is, subclasses can extend the parent class.

3. Subclasses can implement the methods of the parent class in their own way. (Introduction later).

Learning to inherit must have these three things: constructors, protected keywords, upward transformation

2.2 Constructors

By the preceding we know that subclasses can inherit the properties and methods of the parent class, except for those private ones, which are---constructors that the subclass cannot inherit. For a constructor, it can only be called, not inherited. Call the construction method of the parent class we can use Super ().

The build process is "outward" from the parent class, that is, starting from the parent class to the sub-class level to complete the build. And we don't show the constructor that references the parent class, which is the smart thing about Java: The compiler will call the constructor of the parent class by default for the child class.

However, this default call to the constructor of the parent class is a prerequisite: the parent class has a default constructor. If the parent class does not have a default constructor, we will have to show the use of super () to call the parent class constructor, or the compiler will error: Cannot find a constructor that conforms to the parent class.

For subclasses, it is important to initialize the constructor correctly, and only if there is only one way to guarantee this: the parent class constructor is called in the constructor to complete the initialization, and the parent class constructor has all the knowledge and the ability to perform the initialization of the parent class.

For inheritance, subclasses call the constructor of the parent class by default, but if there is no default parent class constructor, the subclass must display the constructor for the specified parent class, and must be the first thing to do in the subclass constructor (the first line of code).

2.3 Protected Keywords

The private access modifier is the best choice for encapsulation, but this is based on the ideal world, and sometimes we need it: we need to hide something as close to the world as possible, but still allow members of the subclass to access it. This time you need to use the protected.

For protected, it indicates that he is private to the class user, but is accessible to any subclass that inherits from this class, or any other class that is in the same package.

2.4 Upward transformation

In the above inheritance we talked about the is-a of inheritance is the relationship between cats and animals, so we can say that cats are animals, or that cats are a kind of animals. This way the cat is seen as an animal or upward transformation.

Three, polymorphic

3.1 Polymorphism Overview

The so-called polymorphism refers to the specific type of reference variable defined in the program and the method call issued by the reference variable is not determined during programming, but is determined during the program's run, that is, a reference to which the variable bottom will point to which class of the instance object, the reference variable emitted by the method call is the method implemented in the class, Must be determined by the time the program is running. Because when the program is run to determine the specific class, so that, without modifying the source code, you can bind the reference variable to a variety of different class implementations, resulting in the invocation of the specific method of the reference change, that is, do not modify the program code can be changed when the program runs the specific code, so that the program can select multiple running state, This is polymorphism.

So for polymorphism we can summarize as follows:

A parent class reference to a subclass because it has been transformed upward, it can only access methods and properties that are owned in the parent class, and the reference is not available for methods that exist in the subclass and that do not exist in the parent class, although the method is overloaded. If subclasses override some of the methods in the parent class, they must be called using the methods defined in the subclass (dynamic joins, dynamic calls).

For object-oriented, polymorphism is divided into compile-time polymorphism and run-time polymorphism. When editing the polymorphism is static, mainly refers to the method of overloading, it is based on the parameter list to distinguish between different functions, by editing will become two different functions, at runtime is not polymorphic. While the runtime polymorphism is dynamic, it is implemented by dynamic binding, which is what we call polymorphism.

3.2 Realization conditions of polymorphism

In the beginning, it was mentioned that inheritance was prepared for polymorphic implementations. Subclass Child inherits the parent class father, we can write a reference to the parent class type of the child class, which can handle either the parent class Father object or the subclass child object, when the same message is sent to the child class or the parent class object. The object performs different behavior depending on the reference to which it belongs, which is polymorphic. That is, polymorphism is the same message that makes different classes respond differently.

There are three prerequisites for implementing polymorphism in Java: inheritance, rewriting, and upward transformation.

Inheritance: Subclasses and parent classes that have inheritance relationships must exist in polymorphism.

Rewrite: Subclasses redefine some methods in the parent class and call the methods of the subclasses when they are called.

Upward transformation: In polymorphic, a reference to a subclass needs to be assigned to the parent class object, so that the reference can have the ability to invoke methods and subclasses of the parent class.

Only by satisfying the above three conditions can we use uniform logic implementation code in the same inheritance structure to handle different objects, thus achieving different behavior.

For Java, its polymorphic implementation mechanism follows a principle: When a Superclass object references a variable that references a subclass object, the type of the referenced object rather than the type of the reference variable determines which member method to call, but the method that is called must be defined in the superclass, that is, the quilt class overrides the method.

3.3 Realization Form

There are two forms in Java that enable polymorphism: inheritance and interfaces.

3.2.1, multi-state based on inheritance implementation

The implementation mechanism based on inheritance mainly manifests in the rewriting of some methods by the parent class and one or more subclasses inheriting the parent class, and the rewriting of the same method by many subclasses can show different behavior.

The polymorphism based on the implementation of inheritance can be summarized as follows: For a parent class type that references a subclass, when the reference is processed, it is applied to all subclasses that inherit the parent class, the subclass object is different, the implementation of the method is different, and the behavior resulting from performing the same action is different.

If the parent class is an abstract class, then the subclass must implement all the abstract methods in the parent class, so that all subclasses of the parent class must have a unified external interface, but the concrete implementations within it can vary. This allows us to use the uniform interface provided by the top-level class to handle the method at that level.

3.2.2, multi-state based on interface implementation

Inheritance is manifested by overriding several different subclasses of the same method of the parent class, which can be realized by implementing the interface and overwriting several different classes of the same method in the interface.

In polymorphic interfaces, a reference to an interface must be an instance program that specifies a class that implements the interface, executing the corresponding method at run time, based on the actual type of the object reference.

Inheritance is a single inheritance and can only provide a consistent service interface for a set of related classes. But the interface can be multi-inheritance multi-implementation, it can use a set of related or irrelevant interfaces for combination and expansion, can provide a consistent service interface. So it has better flexibility than inheritance.

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.