🗊Презентация Object oriented programming in python

Нажмите для полного просмотра!
Object oriented programming in python, слайд №1Object oriented programming in python, слайд №2Object oriented programming in python, слайд №3Object oriented programming in python, слайд №4Object oriented programming in python, слайд №5Object oriented programming in python, слайд №6Object oriented programming in python, слайд №7Object oriented programming in python, слайд №8Object oriented programming in python, слайд №9Object oriented programming in python, слайд №10Object oriented programming in python, слайд №11Object oriented programming in python, слайд №12Object oriented programming in python, слайд №13Object oriented programming in python, слайд №14Object oriented programming in python, слайд №15Object oriented programming in python, слайд №16Object oriented programming in python, слайд №17Object oriented programming in python, слайд №18Object oriented programming in python, слайд №19Object oriented programming in python, слайд №20Object oriented programming in python, слайд №21Object oriented programming in python, слайд №22Object oriented programming in python, слайд №23Object oriented programming in python, слайд №24Object oriented programming in python, слайд №25Object oriented programming in python, слайд №26Object oriented programming in python, слайд №27Object oriented programming in python, слайд №28Object oriented programming in python, слайд №29Object oriented programming in python, слайд №30Object oriented programming in python, слайд №31Object oriented programming in python, слайд №32Object oriented programming in python, слайд №33Object oriented programming in python, слайд №34Object oriented programming in python, слайд №35Object oriented programming in python, слайд №36

Содержание

Вы можете ознакомиться и скачать презентацию на тему Object oriented programming in python. Доклад-сообщение содержит 36 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Object Oriented Programming
in Python
Описание слайда:
Object Oriented Programming in Python

Слайд 2





Agenda
Introduction 
Objects, Types and Classes 
Class Definition
Class Instantiation
Constructor and Destructor 
Lifetime of an Object 
Encapsulation and Access to Properties 
Polymorphism 
Relations between classes 
Inheritance and Multiple Inheritance
"New" and "Classic" Classes
Metaclasses 
Aggregation.  Containers.  Iterators
Methods 
Methods
Static Methods 
Class Methods
Multimethods (Multiple Dispatch)
Object Persistence
Описание слайда:
Agenda Introduction Objects, Types and Classes Class Definition Class Instantiation Constructor and Destructor Lifetime of an Object Encapsulation and Access to Properties Polymorphism Relations between classes Inheritance and Multiple Inheritance "New" and "Classic" Classes Metaclasses Aggregation. Containers. Iterators Methods Methods Static Methods Class Methods Multimethods (Multiple Dispatch) Object Persistence

Слайд 3





Introduction. It’s all objects…
Everything in Python is really an object.
We’ve seen hints of this already…


These look like Java or C++ method calls.
New object classes can easily be defined in addition to these built-in data-types.
In fact, programming in Python is typically done in an object oriented fashion.
Описание слайда:
Introduction. It’s all objects… Everything in Python is really an object. We’ve seen hints of this already… These look like Java or C++ method calls. New object classes can easily be defined in addition to these built-in data-types. In fact, programming in Python is typically done in an object oriented fashion.

Слайд 4





Objects, names and references
All values are objects
A variable is a name referencing an object
An object may have several names referencing it
Important when modifying objects in-place!
You may have to make proper copies to get the effect you want
For immutable objects (numbers, strings), this is never a problem
Описание слайда:
Objects, names and references All values are objects A variable is a name referencing an object An object may have several names referencing it Important when modifying objects in-place! You may have to make proper copies to get the effect you want For immutable objects (numbers, strings), this is never a problem

Слайд 5





Class Definition 
For clarity, in the following discussion we consider the definition of class in terms of syntax. To determine the class, you use class operator:


In a class can be basic (parent) classes (superclasses), which (if any) are listed in parentheses after the defined class. 
The smallest possible class definition looks like this:
Описание слайда:
Class Definition For clarity, in the following discussion we consider the definition of class in terms of syntax. To determine the class, you use class operator: In a class can be basic (parent) classes (superclasses), which (if any) are listed in parentheses after the defined class. The smallest possible class definition looks like this:

Слайд 6





Class Definition
In the terminology of the Python members of the class are called attributes, functions of the class - methods and fields of the class - properties (or simply attributes).
Definitions of methods are similar to the definitions of functions, but (with some exceptions, of which below) methods always have the first argument, called on the widely accepted agreement self: 
Definitions of attributes - the usual assignment operators that connect some of the values with attribute names:
Описание слайда:
Class Definition In the terminology of the Python members of the class are called attributes, functions of the class - methods and fields of the class - properties (or simply attributes). Definitions of methods are similar to the definitions of functions, but (with some exceptions, of which below) methods always have the first argument, called on the widely accepted agreement self: Definitions of attributes - the usual assignment operators that connect some of the values with attribute names:

Слайд 7





Class Definition
In Python a class is not something static after the definition, so you can add attributes and after:
Описание слайда:
Class Definition In Python a class is not something static after the definition, so you can add attributes and after:

Слайд 8





Class Instantiation
To instantiate a class, that is, create an instance of the class, simply call the class name and specify the constructor parameters:
__init__ is the default constructor. 
self refers to the object itself, like this in Java.
Описание слайда:
Class Instantiation To instantiate a class, that is, create an instance of the class, simply call the class name and specify the constructor parameters: __init__ is the default constructor. self refers to the object itself, like this in Java.

Слайд 9





Class Instantiation
By overriding the class method __new__, you can control the process of creating an instance of the class.  This method is called before the method __init__ and should return a new instance, or None (in the latter case will be called __new__ of the parent class).
Method __new__ is used to control the creation of unchangeable (immutable) objects, managing the creation of objects in cases when __init__ is not invoked.
Описание слайда:
Class Instantiation By overriding the class method __new__, you can control the process of creating an instance of the class. This method is called before the method __init__ and should return a new instance, or None (in the latter case will be called __new__ of the parent class). Method __new__ is used to control the creation of unchangeable (immutable) objects, managing the creation of objects in cases when __init__ is not invoked.

Слайд 10





Class Instantiation
The following code demonstrates one of the options for implementing Singleton pattern:
Описание слайда:
Class Instantiation The following code demonstrates one of the options for implementing Singleton pattern:

Слайд 11





Constructor and Destructor 
Special methods are invoked at instantiation of the class (constructor) and disposal of the class (destructor). In Python is implemented automatic memory management, so the destructor is required very often, for resources, that require an explicit release. 
 The next class has a constructor and destructor:
Описание слайда:
Constructor and Destructor Special methods are invoked at instantiation of the class (constructor) and disposal of the class (destructor). In Python is implemented automatic memory management, so the destructor is required very often, for resources, that require an explicit release. The next class has a constructor and destructor:

Слайд 12





Lifetime of an object
Without using any special means lifetime of the object defined in the Python program does not go beyond of run-time process of this program. 
To overcome this limitation, there are different possibilities: from object storage in a simple database (shelve), application of ORM to the use of specialized databases with advanced features (eg, ZODB, ZEO). All these tools help make objects persistent. Typically, when write an object it is serialized, and when read - deserializated.
Описание слайда:
Lifetime of an object Without using any special means lifetime of the object defined in the Python program does not go beyond of run-time process of this program. To overcome this limitation, there are different possibilities: from object storage in a simple database (shelve), application of ORM to the use of specialized databases with advanced features (eg, ZODB, ZEO). All these tools help make objects persistent. Typically, when write an object it is serialized, and when read - deserializated.

Слайд 13





Encapsulation and access to properties
Encapsulation is one of the key concepts of OOP. All values in Python are objects that encapsulate code (methods) & data and provide users a public interface. Methods and data of an object are accessed through its attributes. 
Hiding information about the internal structure of the object is performed in Python at the level of agreement among programmers about which attributes belong to the public class interface, and which - to its internal implementation.
A single underscore in the beginning of the attribute name indicates that the method is not intended for use outside of class methods (or out of functions and classes of the module), but the attribute is still available by this name.
Two underscores in the beginning of the name give somewhat greater protection: the attribute is no longer available by this name. The latter is used quite rarely.
Описание слайда:
Encapsulation and access to properties Encapsulation is one of the key concepts of OOP. All values in Python are objects that encapsulate code (methods) & data and provide users a public interface. Methods and data of an object are accessed through its attributes. Hiding information about the internal structure of the object is performed in Python at the level of agreement among programmers about which attributes belong to the public class interface, and which - to its internal implementation. A single underscore in the beginning of the attribute name indicates that the method is not intended for use outside of class methods (or out of functions and classes of the module), but the attribute is still available by this name. Two underscores in the beginning of the name give somewhat greater protection: the attribute is no longer available by this name. The latter is used quite rarely.

Слайд 14





Encapsulation and access to properties
There is a significant difference between these attributes and personal (private) members of the class in languages like C++ or Java: attribute is still available, but under the name of the form _ClassName__AttributeName, and each time the Python will modify the name, depending on the instance of which class is handling to attribute.
Thus, the parent and child classes can have an attribute name, for example, __f, but will not interfere with each other.
Описание слайда:
Encapsulation and access to properties There is a significant difference between these attributes and personal (private) members of the class in languages like C++ or Java: attribute is still available, but under the name of the form _ClassName__AttributeName, and each time the Python will modify the name, depending on the instance of which class is handling to attribute. Thus, the parent and child classes can have an attribute name, for example, __f, but will not interfere with each other.

Слайд 15





Encapsulation and access to properties
Access to the attribute can be either direct:
…Or using the properties with the specified methods for getting, setting and removing an attribute:
Описание слайда:
Encapsulation and access to properties Access to the attribute can be either direct: …Or using the properties with the specified methods for getting, setting and removing an attribute:

Слайд 16





Encapsulation and access to properties
…Or using the properties with the specified methods for getting, setting and removing an attribute:
Описание слайда:
Encapsulation and access to properties …Or using the properties with the specified methods for getting, setting and removing an attribute:

Слайд 17





Encapsulation and access to properties
There are two ways to centrally control access to attributes. The first is based on method overloading __getattr__(), __setattr__(), __delattr__(), and the second - the method __getattribute__().
The second method helps to manage reading of the existing attributes.
These methods allow you to organize a fully dynamic access to the attributes of the object or that is used very often, and imitation of non-existent attributes.
According to this principle function, for example, all of RPC for Python, imitating the methods and properties that are actually existing on the remote server.
Описание слайда:
Encapsulation and access to properties There are two ways to centrally control access to attributes. The first is based on method overloading __getattr__(), __setattr__(), __delattr__(), and the second - the method __getattribute__(). The second method helps to manage reading of the existing attributes. These methods allow you to organize a fully dynamic access to the attributes of the object or that is used very often, and imitation of non-existent attributes. According to this principle function, for example, all of RPC for Python, imitating the methods and properties that are actually existing on the remote server.

Слайд 18





Polymorphism
In the compiled programming languages, polymorphism is achieved by creating virtual methods, which, unlike non-virtual can be overload in a descendant.
In Python all methods are virtual, which is a natural consequence of allowing access at run time.
Описание слайда:
Polymorphism In the compiled programming languages, polymorphism is achieved by creating virtual methods, which, unlike non-virtual can be overload in a descendant. In Python all methods are virtual, which is a natural consequence of allowing access at run time.

Слайд 19





Polymorphism
Explicitly specifying the name of the class, you can call the method of the parent (as well as any other object):
In general case to get the parent class the function super is applied:
Описание слайда:
Polymorphism Explicitly specifying the name of the class, you can call the method of the parent (as well as any other object): In general case to get the parent class the function super is applied:

Слайд 20





Polymorphism: Virtual Methods
Using a special provided exception NotImplementedError, you can simulate pure virtual methods:
Описание слайда:
Polymorphism: Virtual Methods Using a special provided exception NotImplementedError, you can simulate pure virtual methods:

Слайд 21





Polymorphism: Virtual Methods
 Or, using a python decorator:
Описание слайда:
Polymorphism: Virtual Methods Or, using a python decorator:

Слайд 22





Polymorphism
Changing attribute __class__, you can move an object up or down the inheritance hierarchy (as well as to any other type):
However, in this case, no type conversions are made, so care about data consistency remains entirely on the programmer.
Описание слайда:
Polymorphism Changing attribute __class__, you can move an object up or down the inheritance hierarchy (as well as to any other type): However, in this case, no type conversions are made, so care about data consistency remains entirely on the programmer.

Слайд 23





Inheritance and Multiple Inheritance
Python supports both single inheritance and multiple, allowing the class to be derived from any number of base classes:
In Python (because of the "duck typing" ), the lack of inheritance does not mean that the object can not provide the same interface.
Описание слайда:
Inheritance and Multiple Inheritance Python supports both single inheritance and multiple, allowing the class to be derived from any number of base classes: In Python (because of the "duck typing" ), the lack of inheritance does not mean that the object can not provide the same interface.

Слайд 24





"New" and "Classic" Classes
In versions prior to 2.2, some object-oriented features of Python were noticeably limited. Starting with version 2.2, Python object system has been significantly revised and expanded. However, for compatibility with older versions of Python, it was decided to make two object models: the "classical" type (fully compatible with old code) and "new".  In version Python 3.0 support "old" classes will be removed. 
To build a "new" class is enough to inherit it from other "new".  If you want to create a "pure" class, you can inherit from the object - the parent type for all "new" classes.
All the standard classes - classes of "new" type.
Описание слайда:
"New" and "Classic" Classes In versions prior to 2.2, some object-oriented features of Python were noticeably limited. Starting with version 2.2, Python object system has been significantly revised and expanded. However, for compatibility with older versions of Python, it was decided to make two object models: the "classical" type (fully compatible with old code) and "new". In version Python 3.0 support "old" classes will be removed. To build a "new" class is enough to inherit it from other "new". If you want to create a "pure" class, you can inherit from the object - the parent type for all "new" classes. All the standard classes - classes of "new" type.

Слайд 25





Settlement of access to methods and fields
Behind a quite easy to use mechanism to access attributes in Python lies a fairly complex algorithm. Below is the sequence of actions performed by the interpreter when resolving object.field call (search stops after the first successfully completed step, otherwise there is a transition to the next step):
If the object has method __getattribute__, then it will be called with parameter 'field' (or __setattr__ or __delattr__ depending on the action over the attribute) 
If the object has field __dict__, then object.__dict__['field'] is sought
If object.__class__ has field __slots__, a 'field' is sought in object.__class__.__slots__ 
Checking object.__class__.__dict__['fields'] 
Recursive search is performed on __dict__ of all parent classes 
If the object has method __getattr__, then it is called with a parameter 'field' 
An exception AttributeError is roused.
Описание слайда:
Settlement of access to methods and fields Behind a quite easy to use mechanism to access attributes in Python lies a fairly complex algorithm. Below is the sequence of actions performed by the interpreter when resolving object.field call (search stops after the first successfully completed step, otherwise there is a transition to the next step): If the object has method __getattribute__, then it will be called with parameter 'field' (or __setattr__ or __delattr__ depending on the action over the attribute) If the object has field __dict__, then object.__dict__['field'] is sought If object.__class__ has field __slots__, a 'field' is sought in object.__class__.__slots__ Checking object.__class__.__dict__['fields'] Recursive search is performed on __dict__ of all parent classes If the object has method __getattr__, then it is called with a parameter 'field' An exception AttributeError is roused.

Слайд 26





Aggregation.  Containers.  Iterators 
Aggregation, when one object is part of another, or «HAS-A» relation, is implemented in Python using references. Python has some built-in types of containers: list, dictionary, set. You can define your own container classes with its own logic to access stored objects.
The following class is an example of container-dictionary, supplemented by the possibility of access to the values using the syntax of access to attributes:
Описание слайда:
Aggregation. Containers. Iterators Aggregation, when one object is part of another, or «HAS-A» relation, is implemented in Python using references. Python has some built-in types of containers: list, dictionary, set. You can define your own container classes with its own logic to access stored objects. The following class is an example of container-dictionary, supplemented by the possibility of access to the values using the syntax of access to attributes:

Слайд 27





Aggregation.  Containers.  Iterators
Here's how it works:
Описание слайда:
Aggregation. Containers. Iterators Here's how it works:

Слайд 28





Metaclasses
I’s not always enough to have ordinary capabilities of object-oriented programming. In some cases you want to change the character of the class system: extend the language with new types of classes, change the style of interaction between the classes and the environment, add some additional aspects that affect all classes  used in applications, etc. 
When declare a metaclass, we can take class type as a basis. For example:
Описание слайда:
Metaclasses I’s not always enough to have ordinary capabilities of object-oriented programming. In some cases you want to change the character of the class system: extend the language with new types of classes, change the style of interaction between the classes and the environment, add some additional aspects that affect all classes used in applications, etc. When declare a metaclass, we can take class type as a basis. For example:

Слайд 29





Metaclasses
Описание слайда:
Metaclasses

Слайд 30





Methods
Syntax of a method has no difference from the description of a function, except for its position within a class and specific first formal parameter self, using which the inside of the method can be invoked the class instance itself (the name of self is a convention that Python developers follow to):
Описание слайда:
Methods Syntax of a method has no difference from the description of a function, except for its position within a class and specific first formal parameter self, using which the inside of the method can be invoked the class instance itself (the name of self is a convention that Python developers follow to):

Слайд 31





Static Methods
Описание слайда:
Static Methods

Слайд 32





Class Methods
Описание слайда:
Class Methods

Слайд 33





Multimethods (Multiple Dispatch)
Описание слайда:
Multimethods (Multiple Dispatch)

Слайд 34





Object Persistence
Описание слайда:
Object Persistence

Слайд 35





References
http://docs.python.org/tutorial/classes.html
Объектно-ориентированное программирование на Питоне
OOP in Python after 2.2
Python 101 - Introduction to Python
Python Basic Object-Oriented Programming
Описание слайда:
References http://docs.python.org/tutorial/classes.html Объектно-ориентированное программирование на Питоне OOP in Python after 2.2 Python 101 - Introduction to Python Python Basic Object-Oriented Programming

Слайд 36





 

Questions?
Описание слайда:
Questions?



Похожие презентации
Mypresentation.ru
Загрузить презентацию