Similar presentations:
Python Class_ver2 (2)
1. Unit 11.4A: Object Oriented Programming (ООP)
11.4.1.1 create classes and instances of classes;11.4.1.2 develop methods for the class;
2.
3.
https://docs.python.org/3/tutorial/datastructures.html4.
https://docs.python.org/3/library/sqlite3.html5.
What is Object OrientedProgramming?
Up until now, the programming you have been doing has been procedural.
However, a lot of programs today are Object Oriented.
procedure as a function
Procedural programming is centered on procedures or functions.
But, OOP is centered on creating Objects.
6.
What is Object OrientedProgramming?
Data inside an object is called a data attribute.
Functions, or procedures inside the object are
called methods.
Think of data attributes as variables.
Think of methods as functions or procedures.
7.
In Python, everything is an object.Strings, Integers, Float, lists, dictionaries,
functions, modules etc are all objects.
8.
Classand
Object
and
Instance
9.
Attributesand
Methods
10.
11.
12.
13.
14.
15.
16.
Class + InstanceMethod
Attribute
17. Definitions
• Class - a template• Method or Message - A defined capability of a class
• Field or attribute- A bit of data in a class
• Object or Instance - A particular instance of a class
18. Terminology: Class
Defines the abstract characteristics of a thing (object), including thething's characteristics (its attributes, fields or properties) and the
thing's behaviors (the things it can do, or methods, operations or
features). One might say that a class is a blueprint or factory that
describes the nature of something. For example, the class Dog would
consist of traits shared by all dogs, such as breed and fur color
(characteristics), and the ability to bark and sit (behaviors).
http://en.wikipedia.org/wiki/Object-oriented_programming
19.
A class is a blueprint or template of entities(things) of the same kind. An instance is a
particular realization of a class.
An object contains attributes: data
attributes (or static attribute or variables)
and dynamic behaviors called methods.
In UML diagram, objects are represented by
3-compartment boxes: name, data
attributes and methods, as shown below:
20.
21. Terminology: Instance
One can have an instance of a class or a particular object.The instance is the actual object created at runtime. In
programmer jargon, the Lassie object is an instance of the
Dog class. The set of values of the attributes of a particular
object is called its state. The object consists of state and the
behavior that's defined in the object's class.
Object and Instance are often used interchangeably.
http://en.wikipedia.org/wiki/Object-oriented_programming
22.
23.
24. Terminology: Method
An object's abilities. In language, methods are verbs.Lassie, being a Dog, has the ability to bark. So bark() is one of
Lassie's methods. She may have other methods as well, for example
sit() or eat() or walk() or save_timmy(). Within the program, using a
method usually affects only one particular object; all Dogs can bark,
but you need only one particular dog to do the barking
Method and Message are often used interchangeably.
http://en.wikipedia.org/wiki/Object-oriented_programming
25.
26.
27. Task # 1 Complete the example of Class.
28.
29. Creating a Class
Example 1 : Create Car Classclass : car
attributes : year, mpg and
speed
methods : accelerate and
brake