OOP Flashcards
modularity
organizing principle: different components of sftwr sys divided into separate functional units (think module: collection of closely related classes/functions)
abstraction
distill complicated system down to most fundamental parts
ADT
mathematical model of data structure that specifies type of data stored, supported operations on them, types of parameters of operations
duck typing
treats abstractions implicitly
ABC
only purpose is to serve as base class through inheritance (how Python supports ADT's: defines 1 or more common methods that all implementations of abstraction must have)
encapsulation
should not reveal internal details of implementations
self
serves to identify particular instance upon which a member is invoked
__init__ method
constructor of the class; establishes state of newly created object w/ appropriate instance variables
operator overloading
implementing a specially named method
….ie, + operator overloaded by implementing __add__ method
a + b -> a.__add__(b)
iterator
key behavior: supports special method __next__ : returns next element of collection, if any, or raises StopIteration exception
generator
automatically produces iterator of yielded values
Python provides automatic iterator implementation on classes that define:
__len__ & __getitem__
lazy evaluation
represents the desired elements w/out storing explicitly in memory (rather than creating new instance); ie, range
inheritance
allows new class (child class) to be defined based upon existing class (base/parent/super class)
2 ways subclass differentiates from its superclass
- special existing behavior (overrides method)
- extend: provides new methods