Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Python Programming - VI. Classes and Objects

2 993 vues

Publié le

Publié dans : Technologie
  • hi Jenelyn. sorry medyo di ko pa na-try ung ganyang use case. but I'll send you some good resources that might be helpful. moreover, thumbs-up for your involvement in web mapping and open-source endeavors. :)
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • hello po., Engr. Ranel.. I am developing web mapping application now,. Im using python language and geodjango framework for mapping. I already displayed my geospatial data from my database in django's admin interface,. Tanong ko lang,. possible po buh e group by yong mga geospatial data in admin interface? Land Parcel kasi yong mga data ko sa databse(postgis),. kaya lang one at a time kasi ang pag display sa django's admin,. gusto ko kasi e group sila based sa kanilang land classification kung agricultural, industrial, commercial and etc,.. salamat pooo...
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Python Programming - VI. Classes and Objects

  2. 2. PYTHON PROGRAMMING TOPICS I •Introduction to Python Programming II •Python Basics III •Controlling the Program Flow IV •Program Components: Functions, Classes, Packages, and Modules V •Sequences (List and Tuples), and Dictionaries VI •Object-Based Programming: Classes and Objects VII •Customizing Classes and Operator Overloading VIII •Object-Oriented Programming: Inheritance and Polymorphism IX •Randomization Algorithms X •Exception Handling and Assertions XI •String Manipulation and Regular Expressions XII •File Handling and Processing XIII •GUI Programming Using Tkinter
  4. 4. PROGRAMMING PARADIGMS • Procedural/Imperative (C, FORTRAN, COBOL) • Object-Oriented (C++, Java, C#, Objective-C) Objective-C is used in Apple’s OS X and iOS and for customizing its apps. • Functional Programming (Lisp) Lisp is used for customizing AutoCAD • Logic Programming (Prolog) • Concurrent (Erlang) • Multi-Paradigm (Python, Scala, PHP, JavaScript) •…
  5. 5. PROGRAMMING PARADIGMS http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  6. 6. PROGRAMMING PARADIGMS http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  7. 7. PROGRAMMING PARADIGMS http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  10. 10. PROCEDURE-ORIENTED PROGRAMMING 1/6) Emphasis is on doing things (algorithms). 2/6) Large programs are divided into smaller programs known as functions. 3/6) Most of the functions share global data.
  11. 11. PROCEDURE-ORIENTED PROGRAMMING 4/6) Data are more open around the system from function to function. 5/6) Functions transform data from one form to another. 6/6) Employs top-down approach in program design.
  13. 13. OBJECT-ORIENTED PROGRAMMING The data of an object can be accessed only by the functions associated with that object. Functions of one object can access the functions of other objects.
  14. 14. OBJECT-ORIENTED PROGRAMMING 1/8) Emphasis is on data rather than procedures or algorithms. 2/8) Programs are divided into what are known as objects. 3/8) Data structures are designed such that they characterize the objects. 4/8) Functions that operate on the data are tied together in the data structure.
  15. 15. OBJECT-ORIENTED PROGRAMMING 5/8) Data is hidden and cannot be accessed by external functions. 6/8) Objects may communicate with each other through functions. 7/8) New data and functions can be easily added whenever necessary. 8/8) Follows bottom-up approach in program design.
  16. 16. OBJECT-ORIENTED PROGRAMMING Benefits of OOP: 1/8) Through inheritance, we can eliminate redundant code and extend the use of existing classes which is not possible in procedure-oriented approach. 2/8) We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch which happens procedure-oriented approach. This leads to saving of development time and higher productivity.
  17. 17. OBJECT-ORIENTED PROGRAMMING Benefits of OOP: 3/8) The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program. 4/8) It is possible to have multiple instances of object to co-exist without any interference.
  18. 18. OBJECT-ORIENTED PROGRAMMING Benefits of OOP: 5/8) It is possible to map objects in the problem domain to those in the program. 6/8) It is easy to partition the work in a project based on objects .
  19. 19. OBJECT-ORIENTED PROGRAMMING Benefits of OOP: 7/8) Object oriented systems can be easily upgraded from small to large systems. 8/8) Software complexity can be easily managed.
  20. 20. OBJECT-ORIENTED PROGRAMMING OOP first appeared in the Simula programming language in the 1960s.
  21. 21. OBJECT-ORIENTED PROGRAMMING • Simula was invented by Ole-Johan Dahl and Kristen Nygaard, which influenced C++, Java, and C# • professors Dahl and Nygaard received two very prestigious prizes: 1.) von Neumann medal 2.) Turing prize (the Nobel prize of computer science)
  23. 23. CLASSES • A class is just like a blueprint of a house. • An object is the actual house built from that blueprint. • You could then create numerous houses/objects from a single blueprint.
  24. 24. CLASSES Two main components of an Object/Class (these terms are synonymous/equivalent): • Attributes & Behaviors • Variables & Functions • Fields & Methods • Data Members & Member Functions
  26. 26. CLASSES
  27. 27. THE TIME CLASS | Time1.py
  28. 28. THE TIME CLASS | Time1.py
  29. 29. THE TIME CLASS | Time1.py
  30. 30. THE TIME CLASS
  31. 31. THE TIME CLASS
  32. 32. THE TIME CLASS
  33. 33. THE TIME CLASS
  34. 34. THE TIME CLASS
  35. 35. SPECIAL ATTRIBUTES Classes
  36. 36. SPECIAL ATTRIBUTES Classes
  37. 37. SPECIAL ATTRIBUTES Objects
  38. 38. SPECIAL ATTRIBUTES Objects
  39. 39. OBJECT ATTRIBUTES | Set and Get
  40. 40. OBJECT ATTRIBUTES | Protected Var
  41. 41. OBJECT ATTRIBUTES | Protected Var
  42. 42. OBJECT ATTRIBUTES | Set and Get
  43. 43. OBJECT ATTRIBUTES | Chaining Chaining Comparisons in Other Languages Concise Equivalent in Python
  44. 44. OBJECT ATTRIBUTES | Chaining Chaining Comparisons
  45. 45. OBJECT ATTRIBUTES | Set and Get
  46. 46. OBJECT ATTRIBUTES | Set and Get
  47. 47. OBJECT ATTRIBUTES | Set and Get
  48. 48. OBJECT ATTRIBUTES | Set and Get
  49. 49. OBJECT ATTRIBUTES | Set and Get
  50. 50. OBJECT ATTRIBUTES | Set and Get
  51. 51. OBJECT ATTRIBUTES | Set and Get Raising Exceptions
  52. 52. OBJECT ATTRIBUTES | Set and Get
  53. 53. OBJECT ATTRIBUTES | Set and Get
  54. 54. OBJECT ATTRIBUTES | Set and Get
  55. 55. OBJECT ATTRIBUTES | Set and Get
  56. 56. OBJECT ATTRIBUTES | Set and Get
  57. 57. OBJECT ATTRIBUTES | Private Var
  58. 58. OBJECT ATTRIBUTES | Private Var
  59. 59. OBJECT ATTRIBUTES | Private Var
  60. 60. CONSTRUCTORS | Default Args
  61. 61. CONSTRUCTORS | Default Args
  62. 62. CONSTRUCTORS | Default Args
  63. 63. CONSTRUCTORS | Default Args
  64. 64. CONSTRUCTORS | Default Args
  65. 65. CONSTRUCTORS | Default Args
  66. 66. CONSTRUCTORS | Default Args
  67. 67. CONSTRUCTORS | Default Args
  68. 68. CONSTRUCTORS | Default Args
  69. 69. DESTRUCTORS • method called __del__ • executes when the last reference to an object is deleted or goes out of scope. • specifies no parameters other than self • returns None.
  71. 71. CLASS ATTRIBUTES Class Attributes are used to track the state of all objects/instances of a given class. They are also known as Static Variables There are also Class Behaviors (Static Methods), methods that involve all objects/instances of a given class). In Java, Static Methods are used heavily by the Math class so that you could execute methods without creating an object of the Math class
  73. 73. CLASS ATTRIBUTES Lists are not restricted to homogeneous data types. Python programmers typically use lists to store sequences of homogeneous values (values of the same data type)
  74. 74. CLASS ATTRIBUTES Lists are not restricted to homogeneous data types. Python programmers typically use lists to store sequences of homogeneous values (values of the same data type)
  76. 76. COMPOSITION • Objects usually have attributes of basic/primitive data types (string, integers, boolean, etc) • Composition: when objects whose attributes are themselves references to objects of other classes
  77. 77. COMPOSITION note the gayagaya() method and the tao1.gayagaya(tao2) statement
  83. 83. REFERENCES  Deitel, Deitel, Liperi, and Wiedermann - Python: How to Program (2001).  Disclaimer: Most of the images/information used here have no proper source citation, and I do not claim ownership of these either. I don’t want to reinvent the wheel, and I just want to reuse and reintegrate materials that I think are useful or cool, then present them in another light, form, or perspective. Moreover, the images/information here are mainly used for illustration/educational purposes only, in the spirit of openness of data, spreading light, and empowering people with knowledge. 