Python Object Oriented (OOP)

1.
(: Object Oriented Programming OOP) process-oriented object-oriented
process-oriented: --- focusing on how to do?
1. All steps are completed from start to finish a certain demand gradually
according development requirements, certain functions into a separate code and a function package
3. Finally finished code is to call a function in a different order
features:
1. focus on the steps and processes, does not focus on the division of responsibilities
2. If the demand for complex code becomes very complicated
3. develop complex project, there is no fixed routine, difficult to develop large

Object-oriented: ---- focused on who is going to do?
Comparison function, object-oriented is larger packages, packaged in a plurality of method functions according to the object
1 before the completion of a demand for a first determined duty - to do (Method)
The different determined duty objects in different object inside the encapsulation method (multiple)
3. finalization of the code, so that is the order of the different objects in different ways call
features:
1. focus on objects and responsibilities, different objects assume different responsibilities
2. more suitable complex changes in demand, specially developed to deal with complex projects, providing fixed routine
3. need in process-oriented basis, and then learn some object-oriented syntax

Object-oriented concept has two core
classes: is a general term for a class of things having the same characteristics or behavior of
an object: a concrete existence created out of the class
relations and class objects: first class and then have the object
class is a template object this is based on a template created out of
class just to have an object can have multiple

Class: attribute (common information such matters) and method (you can complete the action)
1. class name: The name of these things (big hump nomenclature)
: a large hump nomenclature
first letter of each word 1 capital
is not between the word and the word is underlined 2.
2. attribute: this class creates objects out what characteristics
3. methods: this class creates objects out what behavior
"" "
" ""
class name to determine the
nouns refining process analysis noun entire business process, that usually is found in class

    示例:

Xiao Ming am 18 years old Height 1.80 every morning to run, things will go
Xiao Zhang, 17, who Height 1.85 Xiao Zhang Xiao Zhang likes to eat things do not run
the class name:
the Person
attributes:
name
height
Age
methods:
RUN ()
EAT ()
"" "

# Define a feline
class Cat:
DEF EAT (Self):
Print ( '% S love fish'% (self.name))
DEF. Drink. (Self):
Print ( 'kitten to drink')

# Create a cat objects
#Print (Cat ())
tom = Cat ()
tom.name = 'Tom'
Print (tom.name)
Print (tom)
tom.drink ()
tom.eat ()

Cat = fentiao ()
Print (fentiao)
fentiao.eat ()

self:
which method a called object, which is a reference to a self object
inside the package method, self invoke methods on the object itself represents the current
at the time of calling the method, the programmer does not need to pass self entry (defined time, the first parameter must be self)

Guess you like

Origin blog.51cto.com/12893781/2408429