Chapter27. A More Realistic Example Flashcards
(4 cards)
Python’s Class System
This is what Python is all about. Object-Oriented-Programming. It is largely a matter of searching for an attribute in a tree of objects, along with a special first argument for functions.
Software design concept: Encapsulation
To wrap up operation logic behind interfaces, such that each operation is coded only once in our program. We want to code operations on objects in class methods, instead of littering them throughout the program. That way, if our needs change in the future, there is just one copy to update – factoring code to remove redundancy and thus optimise maintainability.
OOP The Big Idea: Customisable Hierarchies
The customisable hierarchies we can build with classes provide a much better solution for software that will evolve over time. We can tailor and extend our prior works by coding new subclasses, we can leverage what we’ve already done rather than; starting from scratch each time, or breaking what already works, or introducing multiple copies of code that may all have to be updated in the future. When done right, OOP is a powerful programmer’s ally.
Python’s OOP Machinery
Instance creation - filling out instance attributes Behaviour methods - encapsulating logic in class methods Operator overloading - providing behaviour for built-in operations like printing Customizing behaviour - redefining methods in subclasses to specialise them Customizing constructors - adding initialisation logic to superclass steps