Python: OOP And Common Design Patterns
Overview
This master class is designed to enrich your knowledge on Object Oriented Programming concepts using Python. You will undergo an in-depth learning of OOP design paradigms and apply them in your python code, emphasizing on commonly used design and architectural patterns than can be used to build scalable and maintainable python applications / libraries.Target Audience (who should attend):
- Engineers who wish to understand and/or build large application frameworks using Python
- Engineers who wish to prototype new applications using Python
- Coding enthusiasts who wish to have a strong foundation on OOP concepts using Python
Course Track: Intermediate / Lateral
Pre-requisites:
- Participants should be comfortable with the following technologies:
- Good understanding and knowledge of Core Python programming
language that include – python syntax, flow-control constructs,
python data types, functions and modules, built-in functions
and some built-in modules.
- Good understanding and knowledge of Core Python programming
Course Objectives:
- Learn and understand OOP preliminaries – the pythonic way.
- Design and develop python programs using OOP based design.
- Learn functional programming techniques using Python.
- Learn some commonly used design patterns in Python.
- Learn how to implement AOP patterns using decorators in Python.
- Learn how to leverage concurrent programming using generators and co-routines in Python.
What will NOT be covered:
- Python fundamentals.
- Text processing in Python.
- Process and network automation related library modules/concepts.
- Multi-threading, multiprocessing miscellaneous python libraries
- Web programming or web automation.
- Any third-party library/modules.
Training mode:
- This training program is designed to be a live master class conducted via Google Meet.
-
Most concepts will be explained by live coding – participants are expected to learn by
interacting with the master and trying out short exercises provided by the master.
Training requirements:
-
As the training will be a live master-class, each participant attending the training program must have a working computer/laptop for practice sessions with the following software installed:
- Python 3.10+ installed and configured
[Download available at https://python.org/downloads or from Microsoft Store for Windows users.
You can also use Anaconda Python from https://anaconda.com/downloads ] - Visual-Studio Code with Python extensions enabled.
[Download from https://code.visualstudio.com/Download]
- Python 3.10+ installed and configured
Training Agenda
Day 1
Python Object model
- An overview of Python OO design and architecture.
- Object types, values, identity and attributes.
- Python modules and namespaces.
- Variables, attributes and collection items as references.
- Scope of variables.
- Introspection of objects:
id()
,type()
,dir()
hasattr()
,getattr()
,setattr()
isinstance()
,vars()
str()
,repr()
,bool()
callable()
,iter()
,reversed()
,len()
Classes and Objects
- Python 3 type and object hierarchy.
- Defining classes and instantiating objects.
- Variables vs Attributes: how are they different in Python.
- Classes as first-class instantiatable objects.
- Classes and class attributes.
__name__
,__bases__
,__doc__
,__dict__
,__class__
.
- Instances and instance attributes.
- Class-Instance relationship: rules and bindings.
- Instance methods, class-methods, static-methods and singleton-instance methods.
- Inheritance and Duck-typing.
- OO Design: Pythonisms and best practices.
Day 2
Special methods and implementation of common object contract/interfaces
-
The life-cycle methods:
__new__()
,__init__()
and__del__()
methods.
-
Implementing context management support for an object:
__enter__()
and__exit__()
methods.- Using
contextlib
module for implementing context manager support
-
Exposing object as a value:
- String representations:
__str__()
,__bytes__()
and__repr__()
methods. - Numeric representations:
__int__()
and__float__()
methods. - Boolean representation:
__bool__()
method.
- String representations:
-
Implementing comparability:
__lt__()
,__gt__()
,__le__()
and__ge__()
methods__eq__()
and__ne__()
methods.- Simplifying comparability implementation using
functools.total_ordering
decorator
-
Emulating numeric types:
- Arithmetic support:
__add__()
,__sub__()
,__mul__()
,__mod__()
,__truediv__()
and__pow__()
methods - Bitwise operation support:
__or__()
,__and__()
,__xor__()
,__lshift__()
and__rshift()__
methods. - Using the
operator
module – use-case examples.
- Arithmetic support:
-
Emulating container (custom collection) types:
__len__()
,__contains__()
and__iter__()
methods.- An overview on the iterator protocol.
- Emulating sequence container objects:
__getitem__()
,__add__()
,__mul__()
and__reversed__()
,count()
andindex()
methods.- Mutable sequence emulation using
__setitem__()
,__delitem__()
,__iadd__()
,
__imul__()
,
append()
,
extend()
,
insert()
,
remove()
,
pop()
,
copy()
,
clear()
,
sort()
,
reverse()
` methods.
- Emulating
set
andmapping
containers.
-
Implementing custom callable objects using
__call__()
method -
Customizing attribute accessors:
__getattr__()
,__setattr__()
,__delattr__()
,__dir__()
methods.- Implementing object attributes using
__slots__
support. - Implementing attribute accessors methods using
property()
function and decorator.
- An overview on python meta-programming features and use-cases.
Day 3
Decorators and AOP features
- Creating and using decorators in Python.
- Creating decorators with arguments (parameterized decorators).
- Chaining decorators.
- Dependency injection features: before, after and around filters.
- Implementing decorators using classes.
- Decorating classes and methods of a class.
- Decorating python modules.
- Use-case examples and best practices for implementing decorators.
Pythonic OOP considerations:
- Thinking beyond static OOP (prevalent in C++/Java/C#)
- Un-learning static OOP paradigms (inheritance-based OO design, static methods and members, abstract members, encapsulation using private/public/protected qualifiers, implementing duplicate methods for polymorphism).
- Duck-typing and Monkey-patching: a commonly used python OO pattern.
Functional Programming in Python
- Functions as first-class citizen
- Pure functions vs Functions with side-effects
- Lambda expressions in Python
- Higher-order functions – examples and use-cases
- Monads – the pythonic way
- Partials and Currying functions in Python
Day 4
Creating generators, iterators and co-routines.
- Understanding the concurrency problem while using standard procedural programming paradigm.
- Implementing concurrency using generators in Python.
- Creating a generator using
yield
statement. - Interesting generator patterns in the
itertools
module. - Creating custom iterators for collections.
- Creating co-routines using
yield
expressions. - Creating execution-pipelines using generators and co-routines.
- Using
async
andawait
features to implement co-routines and concurrency patterns. - An overview on the
asyncio
library.
Comprehensions in Python.
- Map-comprehensions and filter-comprehensions.
- List, Tuple, Set and Dictionary comprehensions.
- Generator comprehensions.
- Solving complex iteration based map/filter problems using comprehensions (use-cases with examples).
Day 5
Common pythonic design patterns with use-case examples.
- Implementing
Singletons
,Enforced-Encapsulation
andAccessors
patterns. Generator
/Iterator
protocol.Command-Dispatch
patterns.Publish-Subscribe
patterns.Factory method
andAbstract Factory
patterns.Facade
andStrategy
patternsAdaptor
andProxy
patterns.Chain-of-responsibility
patterns.Object Pool
patterns.Prototype
patterns.Dependency injection
andDecorator
patterns.Memento
patterns.
Garbage collection, memory management, debugging and instrumentation (** optional – based on time availability **)
- An overview on python interpreter and object’s memory layout.
- An overview on python’s garbage collector implementation.
- Using the
gc
module. - Diagnostics and Debugging techniques.
inspect
,pdb
,timeit
,trace
modules.traceback
,code
andframe
objects.- Profiling python applications using
cProfile
module - Profiling memory usage using
memory-profiler
,muppy
andobjgraph
libraries.
Ending notes
Next schedule
from May 15th, 2023 – 9:30 AM IST
About Instructor
Mr. Chandrashekar Babu is a FOSS Technologist and an eminent corporate trainer for various topics in the Linux ecosystem. His journey into the Linux ecosystem started as an enthusiast in the year 1995. Since then, he has been exploring, learning and hacking on various Free/Open Source Software tools and has been delivering training on the same since the year 2003. He maintains his own website at the URL: https://www.chandrashekar.info/
from May 15th, 2023 – 9:30 AM IST
About Instructor
Mr. Chandrashekar Babu is a FOSS Technologist and an eminent corporate trainer for various topics in the Linux ecosystem. His journey into the Linux ecosystem started as an enthusiast in the year 1995. Since then, he has been exploring, learning and hacking on various Free/Open Source Software tools and has been delivering training on the same since the year 2003. He maintains his own website at the URL: https://www.chandrashekar.info/
Training duration: 5 days (6 hours per day)
Training delivery: Online via Google meet
Price: ₹24,000/-