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
super().__init__
calls __ini__ method from parent class
protected members
single underscore; accessible to subclasses, but not public
private members
double underscore; not accessible to public or subclasses
namespace
abstraction that manages all identifiers defined in particular scope (maps each name to its value)
instance namespace
manages attributes specific to individual object (__init__)
class namespace
manages members that are shared by all instances of class
nested class
supports outer class (unrelated to inheritance)
alias
ie, foo = bar: foo alias for bar
shallow vs deep copy
shallow: can add/remove elements without affecting other, but if edit, changes both
deep: the new references its own copies of those objects referenced by original
template method pattern
when an abc provides concrete behaviors that rely upon calls to other abstract behaviors (soon as subclass provides def’s for missing abstract behaviors, inherited concrete behaviors well defined)
metaclass
provides template for class def itself
@abstractmethod
(declares methods to be abstract) don’t provide implementation, but expect concrete subclasses to support those methods