Life is short, I use python--Day6 object-oriented

Source: Internet
Author: User

Directory Outline
1. Introduction to Object-oriented Programming 2. Why use object-oriented development? 3. Object-oriented features: encapsulation, inheritance, polymorphism 4. Classes, methodsprocess-oriented VS object-oriented
Programming Paradigm

Programming is a programmer with a specific syntax + data structure + algorithm composed of code to tell the computer how to perform the task of the process, a program is a programmer in order to get a task result and a set of instructions, is so-called all roads to Rome, the way to achieve a task there are many different ways, The types of programming that are summed up by the characteristics of these different programming methods are the programming paradigm. Different programming paradigms essentially represent different solutions to various types of tasks, and most languages support only one programming paradigm, and of course some languages can support multiple programming paradigms at the same time. Two of the most important programming paradigms are process-oriented programming and object-oriented programming . ---cite the King's blog. Http://www.cnblogs.com/alex3714/articles/5188179.html

Process-oriented programming (procedural programming)

Procedural programming uses a list of instructions to tell the computer what to do step-by-step.
Process-oriented programming dependencies-you guessed-procedures, a procedure contains a set of steps to be computed, and the process is called Top-down languages, which is the procedure from the top to the next step, step by step from top to bottom, to solve the problem from beginning to end. The basic design idea is that the program starts with solving a big problem, and then breaks down a big problem into many small problems or sub-processes, and the process continues to decompose until the small problem is simple enough to be solved within a small step.

The problem is also obvious, that is, if you want to modify the program, you have to modify the part of the dependent parts you also have to modify, for example, if the program at the beginning you set a variable value of 1, but if other sub-procedures rely on the value of 1 of the variable to run correctly, If you change this variable, then you have to modify this process, if there is another subroutine dependent on the sub-process, it will have a series of effects, as the program becomes larger, the maintenance of this method will be more difficult.
So we generally think that if you just write some simple scripts to do some one-off tasks, it's great to use a process-oriented approach, but if the task you're dealing with is complex and needs to be iterative and maintainable, it's the most convenient way to use object-oriented. ---cite the King's blog. Http://www.cnblogs.com/alex3714/articles/5188179.html

In short, the approximate meaning is that process-oriented programming is performed from top to bottom, and if the top value changes, a series of responses will be generated for the following code logic, so we think that if you write some small script programming, the process can be God-oriented, and if you are going to write a bunch of complex logic code, Then object-oriented is more convenient.

Object-Oriented Programming

OOP programming is the use of "class" and "object" to create a variety of models to achieve a real-world description, the use of object-oriented programming because it can make the maintenance and extension of the program easier, and can greatly improve the efficiency of program development, in addition, An object-oriented program can make it easier for people to understand your code logic and make team development easier.

---cite the King's blog. Http://www.cnblogs.com/alex3714/articles/5188179.html

Several core features of object-oriented are as follows:

Class
A class is an abstraction, a blueprint, a prototype for a class of objects that have the same properties. The properties of these objects are defined in the class (variables (data)), a common method, as follows we define a role class

#Author:sean SirclassRole ():def __init__(self,name,role,weapon,r_list,life_value=100,money=10000): Self.r_list=r_list Self.name=name Self.role=role Self.weapon=WeaponSelf.life_value =Life_value Self.money= MoneydefShot (self):Print('Shooting ...')    defGot_shot (self):        Print("Ah...,i got shot...!")    defBuy_gun (self,gun_name):Print("just bought%s"%gun_name)

Object objects
An object is an instantiated instance of a class, a class must be instantiated before it can be called in the program, a class can instantiate multiple objects, each object can also have different properties, like human refers to everyone, each person refers to specific objects, people and people before there is a common, there are different---cite Wang blog. Http://www.cnblogs.com/alex3714/articles/5188179.html

The so-called object is a substance that is instantiated on a class, which can presumably be understood as a template for certain substances with the same characteristics, whereas an object is a substance created by a template.

God made man, the class of man is to have "five senses, limbs, viscera and so on" composition, when caused by a person, then this person is a template by the example of an object

Encapsulation Package
The assignment of the data in the class, the internal invocation is transparent to the external user, which makes the class A capsule or container, with the data and methods of the class in the bread---cite the King blog. Http://www.cnblogs.com/alex3714/articles/5188179.html

In object-oriented programming, a class encapsulates the required data (or the properties of a class) and the operation of the data (or the behavior of a class) in a class, called the class's member variables and methods (or member functions), respectively. This programmatic feature of encapsulating member variables and member functions is called encapsulation.

Inheritance inheritance
A class can derive a subclass, a property, a method defined in the parent class, automatic quilt class inherit father and son.

Polymorphism Polymorphism
State is an important feature of object-oriented, simple point: "An interface, a variety of implementations," refers to a base class derived from a different subclass, and each subclass inherits the same method name, but also the method of the parent class to do a different implementation, this is the same thing shows a variety of forms.
Programming is actually a process of abstracting the concrete world, which is a manifestation of abstraction, abstracting the common denominator of a series of specific things, and then through this abstract thing, and dialogue with different concrete things.
Sending the same message to different classes of objects will have different behavior. For example, if your boss lets all employees start working at nine o'clock, he says "get started" at nine o'clock, instead of saying to the salesperson: "Start a sales job," say to the technician, "Start technical work", because "employee" is an abstract thing, so long as the employee can start to work, He knows that. As for each employee, of course, they do their job and do their jobs.
Polymorphism allows the object of a subclass to be used as an object of the parent class, a reference to a parent type to an object of its subtype, and the method called is the method of that subtype. The code that references and invokes the method is already determined before it is compiled, and the object pointed to by the reference can be dynamically bound during run time

Life is short, I use python--Day6 object-oriented

Related Article

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.