mastering object oriented python

634 971 0
mastering object oriented python

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... the concepts behind Python' s special method names The subject of special methods fills the first seven chapters Here, we'll provide some background that may be of help in understanding Part 1, Pythonic Classes via Special Methods We will try to avoid digressing into the foundations of Python object- oriented programming We're assuming that you've already read the Python 3 Object Oriented Programming... compare various object- oriented designs to see which has better performance It's important to weigh objective evidence along with the more subjective consideration of how well the code seems to reflect the problem domain We'll look at the object- oriented use of the unittest and doctest modules These are essential ingredients in writing software that are known to actually work A good object- oriented design... Retrieving Objects via SQLite 327 Analyzing persistent object use cases 300 The ACID properties 301 Creating a shelf 302 Designing shelvable objects 303 Designing keys for our objects 303 Generating surrogate keys for objects 305 Designing a class with a simple key 305 Designing classes for containers or collections 308 Referring to objects via foreign keys 308 Designing CRUD operations for complex objects... of objects: class SomeClass: pass class Test_EmptyClass( TestAccess ): def setUp( self ): self .object= SomeClass() class Test_Namespace( TestAccess ): def setUp( self ): self .object= types.SimpleNamespace() class Test _Object( TestAccess ): def setUp( self ): self .object= object( ) The subclasses of the TestAccess classes each provide the required setUp() method Each method builds a different kind of object. .. JSON, YAML, pickle, XML, and CSV • Chapter 10, Storing and Retrieving Objects via Shelve, explains basic database operations with Python modules, such as shelve (and dbm) • Chapter 11, Storing and Retrieving Objects via SQLite, moves to the more complex world of SQL and the relational database Because SQL features don't match object- oriented programming features well, we have an impedance mismatch problem... advanced Python You'll need to be quite familiar with Python 3 You'll also benefit from having fairly large or complex problems to solve If you are a skilled programmer with the other languages, you may find this book helpful if you want to switch to Python This book doesn't introduce syntax or other foundational concepts Advanced Python 2 programmers may find this helpful when they switch to Python. .. one of the early problem domains for object- oriented programming This is an area where object- oriented programming works out particularly elegantly For more information, see http://en.wikipedia.org/ wiki/Simula Also see An Introduction to Programming in Simula by Rob Pooley This chapter will provide some background in tools that are essential for writing complete Python programs and packages We'll use... databases, persistence, and objects The SQL data model – rows and tables CRUD processing via SQL DML statements Querying rows with the SQL SELECT statement SQL transactions and the ACID properties Designing primary and foreign database keys Processing application data with SQL Implementing class-like processing in pure SQL Mapping Python objects to SQLite BLOB columns Mapping Python objects to database rows... conform to PEP-8 in every single particular detail of the name choice or punctuation As we move towards achieving mastery over object- oriented Python, we'll spend a great deal of time reading Python code from a variety of sources We'll observe wide variability even within the Python Standard Library modules Rather than presenting examples that are all perfectly consistent, we've opted for some inconsistency,... been thoroughly stated elsewhere In this book, we will focus solely on Python 3 We'll refer to a number of common, object- oriented design patterns We'll try to avoid repeating the presentation in Packt's Learning Python Design Patterns About casino Blackjack If you're unfamiliar with the casino game of Blackjack, here's an overview The objective is to accept cards from the dealer to create a hand that .

Ngày đăng: 27/07/2014, 16:45

Mục lục

  • Some Preliminaries

    • About casino Blackjack

      • Playing the game

      • Object design for simulating Blackjack

      • Performance – the timeit module

      • Testing – unittest and doctest

        • Unit testing and technology spikes

        • Docstrings – RST markup and documentation tools

        • About special method names

        • Part 1: Pythonic Classes via Special Methods

          • Chapter 1: The __init__() Method

            • The implicit superclass – object

            • The base class object __init__() method

            • Implementing __init__() in a superclass

            • Using __init__() to create manifest constants

            • Simplicity using mapping and class objects

              • Two parallel mappings

              • Mapping to a tuple of values

              • The partial function solution

              • Fluent APIs for factories

              • Implementing __init__() in each subclass

              • Simple composite objects

                • Wrapping a collection class

                • Extending a collection class

                • More requirements and another design

                • Complex composite objects

                  • Complete composite object initialization

                  • Stateless objects without __init__()

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan