diff --git a/examples/C05_asyncio/01_generators/1_counter.py b/examples/A17_generators/1_counter.py similarity index 100% rename from examples/C05_asyncio/01_generators/1_counter.py rename to examples/A17_generators/1_counter.py diff --git a/examples/C05_asyncio/01_generators/2_memory_footprint.py b/examples/A17_generators/2_memory_footprint.py similarity index 100% rename from examples/C05_asyncio/01_generators/2_memory_footprint.py rename to examples/A17_generators/2_memory_footprint.py diff --git a/examples/C05_asyncio/01_generators/3_fibonacci.py b/examples/A17_generators/3_fibonacci.py similarity index 100% rename from examples/C05_asyncio/01_generators/3_fibonacci.py rename to examples/A17_generators/3_fibonacci.py diff --git a/examples/C05_asyncio/01_generators/4_delegation.py b/examples/A17_generators/4_delegation.py similarity index 100% rename from examples/C05_asyncio/01_generators/4_delegation.py rename to examples/A17_generators/4_delegation.py diff --git a/examples/C05_asyncio/01_generators/5_recursive.py b/examples/A17_generators/5_recursive.py similarity index 100% rename from examples/C05_asyncio/01_generators/5_recursive.py rename to examples/A17_generators/5_recursive.py diff --git a/examples/C05_asyncio/01_generators/generator_concept.py b/examples/A17_generators/generator_concept.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_concept.py rename to examples/A17_generators/generator_concept.py diff --git a/examples/C05_asyncio/01_generators/generator_delegation.py b/examples/A17_generators/generator_delegation.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_delegation.py rename to examples/A17_generators/generator_delegation.py diff --git a/examples/C05_asyncio/01_generators/generator_expression.py b/examples/A17_generators/generator_expression.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_expression.py rename to examples/A17_generators/generator_expression.py diff --git a/examples/C05_asyncio/01_generators/generator_expression_complex.py b/examples/A17_generators/generator_expression_complex.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_expression_complex.py rename to examples/A17_generators/generator_expression_complex.py diff --git a/examples/C05_asyncio/01_generators/generator_expression_equivalent.py b/examples/A17_generators/generator_expression_equivalent.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_expression_equivalent.py rename to examples/A17_generators/generator_expression_equivalent.py diff --git a/examples/C05_asyncio/01_generators/generator_expression_walrus.py b/examples/A17_generators/generator_expression_walrus.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_expression_walrus.py rename to examples/A17_generators/generator_expression_walrus.py diff --git a/examples/C05_asyncio/01_generators/generator_infinite.py b/examples/A17_generators/generator_infinite.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_infinite.py rename to examples/A17_generators/generator_infinite.py diff --git a/examples/C05_asyncio/01_generators/generator_nested.py b/examples/A17_generators/generator_nested.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_nested.py rename to examples/A17_generators/generator_nested.py diff --git a/examples/C05_asyncio/01_generators/generator_passing.py b/examples/A17_generators/generator_passing.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_passing.py rename to examples/A17_generators/generator_passing.py diff --git a/examples/C05_asyncio/01_generators/generator_recursive.py b/examples/A17_generators/generator_recursive.py similarity index 100% rename from examples/C05_asyncio/01_generators/generator_recursive.py rename to examples/A17_generators/generator_recursive.py diff --git a/examples/C05_asyncio/01_generators/letter_generator.py b/examples/A17_generators/letter_generator.py similarity index 100% rename from examples/C05_asyncio/01_generators/letter_generator.py rename to examples/A17_generators/letter_generator.py diff --git a/examples/C05_asyncio/02_coroutines/1_decorate.py b/examples/A18_coroutines/1_decorate.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/1_decorate.py rename to examples/A18_coroutines/1_decorate.py diff --git a/examples/C05_asyncio/02_coroutines/2_average.py b/examples/A18_coroutines/2_average.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/2_average.py rename to examples/A18_coroutines/2_average.py diff --git a/examples/C05_asyncio/02_coroutines/3_bytestream.py b/examples/A18_coroutines/3_bytestream.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/3_bytestream.py rename to examples/A18_coroutines/3_bytestream.py diff --git a/examples/C05_asyncio/02_coroutines/4_pipeline.py b/examples/A18_coroutines/4_pipeline.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/4_pipeline.py rename to examples/A18_coroutines/4_pipeline.py diff --git a/examples/C05_asyncio/02_coroutines/5_fsm.py b/examples/A18_coroutines/5_fsm.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/5_fsm.py rename to examples/A18_coroutines/5_fsm.py diff --git a/examples/C05_asyncio/02_coroutines/6_recursion.py b/examples/A18_coroutines/6_recursion.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/6_recursion.py rename to examples/A18_coroutines/6_recursion.py diff --git a/examples/A18_meta_classes/__init__.py b/examples/A18_coroutines/__init__.py similarity index 100% rename from examples/A18_meta_classes/__init__.py rename to examples/A18_coroutines/__init__.py diff --git a/examples/C05_asyncio/02_coroutines/coroutine_chaining.py b/examples/A18_coroutines/coroutine_chaining.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/coroutine_chaining.py rename to examples/A18_coroutines/coroutine_chaining.py diff --git a/examples/C05_asyncio/02_coroutines/coroutine_execution.py b/examples/A18_coroutines/coroutine_execution.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/coroutine_execution.py rename to examples/A18_coroutines/coroutine_execution.py diff --git a/examples/C05_asyncio/02_coroutines/coroutine_interface.py b/examples/A18_coroutines/coroutine_interface.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/coroutine_interface.py rename to examples/A18_coroutines/coroutine_interface.py diff --git a/examples/C05_asyncio/01_generators/__init__.py b/examples/A21_meta_classes/__init__.py similarity index 100% rename from examples/C05_asyncio/01_generators/__init__.py rename to examples/A21_meta_classes/__init__.py diff --git a/examples/A18_meta_classes/class_create_with_type.py b/examples/A21_meta_classes/class_create_with_type.py similarity index 100% rename from examples/A18_meta_classes/class_create_with_type.py rename to examples/A21_meta_classes/class_create_with_type.py diff --git a/examples/A18_meta_classes/demo_abstract.py b/examples/A21_meta_classes/demo_abstract.py similarity index 100% rename from examples/A18_meta_classes/demo_abstract.py rename to examples/A21_meta_classes/demo_abstract.py diff --git a/examples/A18_meta_classes/demo_basic.py b/examples/A21_meta_classes/demo_basic.py similarity index 100% rename from examples/A18_meta_classes/demo_basic.py rename to examples/A21_meta_classes/demo_basic.py diff --git a/examples/A18_meta_classes/demo_conflict.py b/examples/A21_meta_classes/demo_conflict.py similarity index 100% rename from examples/A18_meta_classes/demo_conflict.py rename to examples/A21_meta_classes/demo_conflict.py diff --git a/examples/A18_meta_classes/demo_debug.py b/examples/A21_meta_classes/demo_debug.py similarity index 100% rename from examples/A18_meta_classes/demo_debug.py rename to examples/A21_meta_classes/demo_debug.py diff --git a/examples/A18_meta_classes/demo_declarative_api.py b/examples/A21_meta_classes/demo_declarative_api.py similarity index 100% rename from examples/A18_meta_classes/demo_declarative_api.py rename to examples/A21_meta_classes/demo_declarative_api.py diff --git a/examples/A18_meta_classes/demo_decorator.py b/examples/A21_meta_classes/demo_decorator.py similarity index 100% rename from examples/A18_meta_classes/demo_decorator.py rename to examples/A21_meta_classes/demo_decorator.py diff --git a/examples/A18_meta_classes/demo_final.py b/examples/A21_meta_classes/demo_final.py similarity index 100% rename from examples/A18_meta_classes/demo_final.py rename to examples/A21_meta_classes/demo_final.py diff --git a/examples/A18_meta_classes/demo_gui.py b/examples/A21_meta_classes/demo_gui.py similarity index 100% rename from examples/A18_meta_classes/demo_gui.py rename to examples/A21_meta_classes/demo_gui.py diff --git a/examples/A18_meta_classes/demo_indexing.py b/examples/A21_meta_classes/demo_indexing.py similarity index 100% rename from examples/A18_meta_classes/demo_indexing.py rename to examples/A21_meta_classes/demo_indexing.py diff --git a/examples/A18_meta_classes/demo_registrar.py b/examples/A21_meta_classes/demo_registrar.py similarity index 100% rename from examples/A18_meta_classes/demo_registrar.py rename to examples/A21_meta_classes/demo_registrar.py diff --git a/examples/A18_meta_classes/demo_reloading.py b/examples/A21_meta_classes/demo_reloading.py similarity index 100% rename from examples/A18_meta_classes/demo_reloading.py rename to examples/A21_meta_classes/demo_reloading.py diff --git a/examples/A18_meta_classes/demo_singleton.py b/examples/A21_meta_classes/demo_singleton.py similarity index 100% rename from examples/A18_meta_classes/demo_singleton.py rename to examples/A21_meta_classes/demo_singleton.py diff --git a/examples/A18_meta_classes/demo_typed.py b/examples/A21_meta_classes/demo_typed.py similarity index 100% rename from examples/A18_meta_classes/demo_typed.py rename to examples/A21_meta_classes/demo_typed.py diff --git a/examples/A18_meta_classes/snippets.py b/examples/A21_meta_classes/snippets.py similarity index 100% rename from examples/A18_meta_classes/snippets.py rename to examples/A21_meta_classes/snippets.py diff --git a/examples/C05_asyncio/02_coroutines/__init__.py b/examples/A24_compatibility/compatibility_imports.py similarity index 100% rename from examples/C05_asyncio/02_coroutines/__init__.py rename to examples/A24_compatibility/compatibility_imports.py diff --git a/examples/A21_import_system/__init__.py b/examples/A25_import_system/__init__.py similarity index 100% rename from examples/A21_import_system/__init__.py rename to examples/A25_import_system/__init__.py diff --git a/examples/A21_import_system/circular/__init__.py b/examples/A25_import_system/circular/__init__.py similarity index 100% rename from examples/A21_import_system/circular/__init__.py rename to examples/A25_import_system/circular/__init__.py diff --git a/examples/A21_import_system/circular/submodule1.py b/examples/A25_import_system/circular/submodule1.py similarity index 100% rename from examples/A21_import_system/circular/submodule1.py rename to examples/A25_import_system/circular/submodule1.py diff --git a/examples/A21_import_system/circular/submodule2.py b/examples/A25_import_system/circular/submodule2.py similarity index 100% rename from examples/A21_import_system/circular/submodule2.py rename to examples/A25_import_system/circular/submodule2.py diff --git a/examples/A21_import_system/export_decorator.py b/examples/A25_import_system/export_decorator.py similarity index 100% rename from examples/A21_import_system/export_decorator.py rename to examples/A25_import_system/export_decorator.py diff --git a/examples/A21_import_system/foo/__init__.py b/examples/A25_import_system/foo/__init__.py similarity index 100% rename from examples/A21_import_system/foo/__init__.py rename to examples/A25_import_system/foo/__init__.py diff --git a/examples/A21_import_system/foo/__main__.py b/examples/A25_import_system/foo/__main__.py similarity index 100% rename from examples/A21_import_system/foo/__main__.py rename to examples/A25_import_system/foo/__main__.py diff --git a/examples/A21_import_system/foo/api/__init__.py b/examples/A25_import_system/foo/api/__init__.py similarity index 100% rename from examples/A21_import_system/foo/api/__init__.py rename to examples/A25_import_system/foo/api/__init__.py diff --git a/examples/A21_import_system/foo/api/submodule1.py b/examples/A25_import_system/foo/api/submodule1.py similarity index 100% rename from examples/A21_import_system/foo/api/submodule1.py rename to examples/A25_import_system/foo/api/submodule1.py diff --git a/examples/A21_import_system/foo/core/__init__.py b/examples/A25_import_system/foo/core/__init__.py similarity index 100% rename from examples/A21_import_system/foo/core/__init__.py rename to examples/A25_import_system/foo/core/__init__.py diff --git a/examples/A21_import_system/foo/core/submodule2.py b/examples/A25_import_system/foo/core/submodule2.py similarity index 100% rename from examples/A21_import_system/foo/core/submodule2.py rename to examples/A25_import_system/foo/core/submodule2.py diff --git a/examples/A21_import_system/foo/gui/__init__.py b/examples/A25_import_system/foo/gui/__init__.py similarity index 100% rename from examples/A21_import_system/foo/gui/__init__.py rename to examples/A25_import_system/foo/gui/__init__.py diff --git a/examples/A21_import_system/foo/gui/submodule3.py b/examples/A25_import_system/foo/gui/submodule3.py similarity index 100% rename from examples/A21_import_system/foo/gui/submodule3.py rename to examples/A25_import_system/foo/gui/submodule3.py diff --git a/examples/A21_import_system/import_absolute.py b/examples/A25_import_system/import_absolute.py similarity index 100% rename from examples/A21_import_system/import_absolute.py rename to examples/A25_import_system/import_absolute.py diff --git a/examples/A21_import_system/import_circular.py b/examples/A25_import_system/import_circular.py similarity index 100% rename from examples/A21_import_system/import_circular.py rename to examples/A25_import_system/import_circular.py diff --git a/examples/A21_import_system/import_conditional.py b/examples/A25_import_system/import_conditional.py similarity index 100% rename from examples/A21_import_system/import_conditional.py rename to examples/A25_import_system/import_conditional.py diff --git a/examples/A21_import_system/import_main_module.py b/examples/A25_import_system/import_main_module.py similarity index 100% rename from examples/A21_import_system/import_main_module.py rename to examples/A25_import_system/import_main_module.py diff --git a/examples/A21_import_system/import_module_objects.py b/examples/A25_import_system/import_module_objects.py similarity index 100% rename from examples/A21_import_system/import_module_objects.py rename to examples/A25_import_system/import_module_objects.py diff --git a/examples/A21_import_system/import_namespaces.py b/examples/A25_import_system/import_namespaces.py similarity index 100% rename from examples/A21_import_system/import_namespaces.py rename to examples/A25_import_system/import_namespaces.py diff --git a/examples/A21_import_system/import_packages.py b/examples/A25_import_system/import_packages.py similarity index 100% rename from examples/A21_import_system/import_packages.py rename to examples/A25_import_system/import_packages.py diff --git a/examples/A21_import_system/import_packages.txt b/examples/A25_import_system/import_packages.txt similarity index 100% rename from examples/A21_import_system/import_packages.txt rename to examples/A25_import_system/import_packages.txt diff --git a/examples/A21_import_system/import_process.py b/examples/A25_import_system/import_process.py similarity index 100% rename from examples/A21_import_system/import_process.py rename to examples/A25_import_system/import_process.py diff --git a/examples/A21_import_system/import_relative.py b/examples/A25_import_system/import_relative.py similarity index 100% rename from examples/A21_import_system/import_relative.py rename to examples/A25_import_system/import_relative.py diff --git a/examples/A21_import_system/import_search_path.py b/examples/A25_import_system/import_search_path.py similarity index 100% rename from examples/A21_import_system/import_search_path.py rename to examples/A25_import_system/import_search_path.py diff --git a/examples/A21_import_system/import_skip_execution.py b/examples/A25_import_system/import_skip_execution.py similarity index 100% rename from examples/A21_import_system/import_skip_execution.py rename to examples/A25_import_system/import_skip_execution.py diff --git a/examples/A21_import_system/import_statements.py b/examples/A25_import_system/import_statements.py similarity index 100% rename from examples/A21_import_system/import_statements.py rename to examples/A25_import_system/import_statements.py diff --git a/examples/A21_import_system/import_sys_path.py b/examples/A25_import_system/import_sys_path.py similarity index 100% rename from examples/A21_import_system/import_sys_path.py rename to examples/A25_import_system/import_sys_path.py diff --git a/examples/A21_import_system/import_tracking.py b/examples/A25_import_system/import_tracking.py similarity index 100% rename from examples/A21_import_system/import_tracking.py rename to examples/A25_import_system/import_tracking.py diff --git a/examples/A21_import_system/rootdir.py b/examples/A25_import_system/rootdir.py similarity index 100% rename from examples/A21_import_system/rootdir.py rename to examples/A25_import_system/rootdir.py diff --git a/examples/B02_solid_principles/single_responsibility_bad.py b/examples/B02_solid_principles/01_bad_single_responsibility.py similarity index 99% rename from examples/B02_solid_principles/single_responsibility_bad.py rename to examples/B02_solid_principles/01_bad_single_responsibility.py index 19eb1a0..2b032bc 100644 --- a/examples/B02_solid_principles/single_responsibility_bad.py +++ b/examples/B02_solid_principles/01_bad_single_responsibility.py @@ -4,6 +4,7 @@ # have only one reason to change. This example bundles reading, # writing and processing into one class, so it breaks SRP. + class MyCustomFileFormat(object): """ This class violates the Single Responsibility Principle because: diff --git a/examples/B02_solid_principles/single_responsibility_good.py b/examples/B02_solid_principles/02_good_single_responsibility.py similarity index 99% rename from examples/B02_solid_principles/single_responsibility_good.py rename to examples/B02_solid_principles/02_good_single_responsibility.py index ffc4b77..01417af 100644 --- a/examples/B02_solid_principles/single_responsibility_good.py +++ b/examples/B02_solid_principles/02_good_single_responsibility.py @@ -3,7 +3,7 @@ # The Single Responsibility Principle (SRP) states that a class should # do only one thing. Here the reading, writing and processing logic # are split into separate classes. - +# # By splitting the class into three classes, we can now reuse the classes in # other parts of the program. A change in one class will not affect the other # classes. This makes the code more maintainable and easier to understand. diff --git a/examples/B02_solid_principles/open_closed_bad.py b/examples/B02_solid_principles/03_bad_open_closed.py similarity index 84% rename from examples/B02_solid_principles/open_closed_bad.py rename to examples/B02_solid_principles/03_bad_open_closed.py index 642a01a..2b96526 100644 --- a/examples/B02_solid_principles/open_closed_bad.py +++ b/examples/B02_solid_principles/03_bad_open_closed.py @@ -1,8 +1,10 @@ # Open/Closed Principle - Bad Example # ------------------------------------------------------------------------------ # The Open/Closed Principle (OCP) states that code should be open for -# extension but closed for modification. Adding a new format here -# requires changing the FileProcessor class, so OCP is violated. +# extension but closed for modification. +# +# Adding a new format here in the example below requires changing the +# FileProcessor class, so the open/closed principle is violated. class FileProcessor(object): diff --git a/examples/B02_solid_principles/open_closed_good.py b/examples/B02_solid_principles/04_good_open_closed.py similarity index 77% rename from examples/B02_solid_principles/open_closed_good.py rename to examples/B02_solid_principles/04_good_open_closed.py index 40f43ee..f022b79 100644 --- a/examples/B02_solid_principles/open_closed_good.py +++ b/examples/B02_solid_principles/04_good_open_closed.py @@ -1,8 +1,11 @@ # Open/Closed Principle - Good Example # ------------------------------------------------------------------------------ # The Open/Closed Principle (OCP) says that classes should be -# extendable without needing to modify their source. FileProcessor -# composes formatter objects so new behaviour can be added safely. +# extendable without needing to modify their source. +# +# By using composition, we can extend the functionality of the FileProcessor +# class without changing its code. This allows us to add new file formats +# without modifying the existing class, adhering to the OCP. class LowercaseFormat(object): diff --git a/examples/B02_solid_principles/liskov_substitution_bad.py b/examples/B02_solid_principles/05_bad_liskov_subsitution.py similarity index 73% rename from examples/B02_solid_principles/liskov_substitution_bad.py rename to examples/B02_solid_principles/05_bad_liskov_subsitution.py index 7a29721..31354dd 100644 --- a/examples/B02_solid_principles/liskov_substitution_bad.py +++ b/examples/B02_solid_principles/05_bad_liskov_subsitution.py @@ -1,8 +1,13 @@ # Liskov Substitution Principle - Bad Example # ------------------------------------------------------------------------------ # The Liskov Substitution Principle (LSP) requires that subclasses -# can stand in for their base class. Here the work method checks -# for `Baby` explicitly, so `Baby` cannot substitute `Human`. +# can stand in for their base class without altering the correctness of the +# program. +# +# Here without the LSP, we have a situation where a subclass (Baby) cannot be +# used in place of its superclass (Human). As a code smell, there is a +# conditional check in the `work` method of the `Human` class that +# checks the type of the object. class Human(object): diff --git a/examples/B02_solid_principles/liskov_substitution_good.py b/examples/B02_solid_principles/06_good_liskov_substitution.py similarity index 79% rename from examples/B02_solid_principles/liskov_substitution_good.py rename to examples/B02_solid_principles/06_good_liskov_substitution.py index 2eccfdb..c17c29f 100644 --- a/examples/B02_solid_principles/liskov_substitution_good.py +++ b/examples/B02_solid_principles/06_good_liskov_substitution.py @@ -2,8 +2,11 @@ # ------------------------------------------------------------------------------ # The Liskov Substitution Principle (LSP) means that objects of a # superclass should be replaceable with objects of its subclasses -# without breaking the program. Each subclass here simply extends -# Human without special checks. +# without breaking the program. +# +# In this example, we have a base class `Human` and two subclasses `Adult` and +# `Baby`. Both subclasses implement all the methods of the `Human` class, +# allowing them to be substituted for `Human` without violating the LSP. class Human(object): @@ -36,7 +39,3 @@ class Baby(Human): def suckle(self): print("{} suckling".format(self.name)) - - - - diff --git a/examples/B02_solid_principles/interface_segregation_bad.py b/examples/B02_solid_principles/07_bad_interface_segregation.py similarity index 81% rename from examples/B02_solid_principles/interface_segregation_bad.py rename to examples/B02_solid_principles/07_bad_interface_segregation.py index 27f5ad1..0ff86b0 100644 --- a/examples/B02_solid_principles/interface_segregation_bad.py +++ b/examples/B02_solid_principles/07_bad_interface_segregation.py @@ -1,9 +1,12 @@ # Interface Segregation Principle - Bad Example # ------------------------------------------------------------------------------ # The Interface Segregation Principle (ISP) advises that clients -# should not be forced to depend on methods they do not use. The -# Device class defines unrelated operations that specific devices -# need to ignore. +# should not be forced to depend on methods they do not use. +# +# In this example, we have a base class `Device` that defines methods +# for powering on, powering off, adjusting volume, and brightness. However, +# the `HeadSet` and `Monitor` classes only use a subset of these methods, +# leading to a violation of the ISP. class Device(object): diff --git a/examples/B02_solid_principles/interface_segregation_good.py b/examples/B02_solid_principles/08_good_interface_segregation.py similarity index 84% rename from examples/B02_solid_principles/interface_segregation_good.py rename to examples/B02_solid_principles/08_good_interface_segregation.py index 997f25d..bb7879a 100644 --- a/examples/B02_solid_principles/interface_segregation_good.py +++ b/examples/B02_solid_principles/08_good_interface_segregation.py @@ -1,8 +1,12 @@ # Interface Segregation Principle - Good Example # ------------------------------------------------------------------------------ # The Interface Segregation Principle (ISP) breaks large interfaces -# into focused ones. Mixins here provide only the operations each -# device actually needs. +# into focused ones. +# +# This example defines a base Device class and several mixins for specific +# functionalities. Each device class inherits from Device and the relevant +# mixins, allowing for a clean separation of concerns and avoiding the need +# for devices to implement methods they do not use. class Device(object): # Defines only the common methods for all devices diff --git a/examples/B02_solid_principles/dependency_inversion_bad.py b/examples/B02_solid_principles/09_bad_dependency_inversion.py similarity index 73% rename from examples/B02_solid_principles/dependency_inversion_bad.py rename to examples/B02_solid_principles/09_bad_dependency_inversion.py index 0e131b2..f7a2e51 100644 --- a/examples/B02_solid_principles/dependency_inversion_bad.py +++ b/examples/B02_solid_principles/09_bad_dependency_inversion.py @@ -1,9 +1,10 @@ # Dependency Inversion Principle - Bad Example # ------------------------------------------------------------------------------ # The Dependency Inversion Principle (DIP) dictates that high level -# modules should not depend on low level ones directly. Calculator -# instantiates Math itself and so is tightly coupled to it. - +# modules should not depend on low level ones directly. +# +# This example violates DIP by hard-coding a dependency on a specific +# math implementation instead of using an abstraction. class Math(object): @@ -20,7 +21,7 @@ class Calculator(object): def __init__(self): - # Code smell: Dependency relationship is hard-coded (dependency) + # CODE SMELL: Math object is hard-coded (dependency) # and not abstracted (injection) self.math = Math() diff --git a/examples/B02_solid_principles/dependency_inversion_good.py b/examples/B02_solid_principles/10_good_dependency_inversion.py similarity index 80% rename from examples/B02_solid_principles/dependency_inversion_good.py rename to examples/B02_solid_principles/10_good_dependency_inversion.py index 5c86ec2..33e54bf 100644 --- a/examples/B02_solid_principles/dependency_inversion_good.py +++ b/examples/B02_solid_principles/10_good_dependency_inversion.py @@ -1,8 +1,13 @@ # Dependency Inversion Principle - Good Example # ------------------------------------------------------------------------------ # The Dependency Inversion Principle (DIP) encourages depending on -# abstractions rather than concrete classes. Calculator receives an -# IMath implementation, decoupling it from a specific Math class. +# abstractions rather than concrete classes. +# +# This example demonstrates a simple math class that adheres to DIP. It defines +# an interface (IMath) that specifies the contract for math operations, +# allowing different implementations to be used without changing the +# dependent code (Calculator). + class IMath(object): """ Simplified interface for junior math class """ diff --git a/examples/B04_secure_design/input_validation.py b/examples/B04_secure_design/01_input_validation.py similarity index 100% rename from examples/B04_secure_design/input_validation.py rename to examples/B04_secure_design/01_input_validation.py diff --git a/examples/B04_secure_design/password_storage_bad.py b/examples/B04_secure_design/02_bad_password_storage.py similarity index 100% rename from examples/B04_secure_design/password_storage_bad.py rename to examples/B04_secure_design/02_bad_password_storage.py diff --git a/examples/B04_secure_design/password_storage_good.py b/examples/B04_secure_design/03_good_password_storage.py similarity index 100% rename from examples/B04_secure_design/password_storage_good.py rename to examples/B04_secure_design/03_good_password_storage.py diff --git a/examples/B04_secure_design/sql_injection_bad.py b/examples/B04_secure_design/04_bad_sql_injection.py similarity index 100% rename from examples/B04_secure_design/sql_injection_bad.py rename to examples/B04_secure_design/04_bad_sql_injection.py diff --git a/examples/B04_secure_design/sql_injection_good.py b/examples/B04_secure_design/05_good_sql_injection.py similarity index 100% rename from examples/B04_secure_design/sql_injection_good.py rename to examples/B04_secure_design/05_good_sql_injection.py diff --git a/examples/B04_secure_design/secret_from_env.py b/examples/B04_secure_design/06_secret_from_env.py similarity index 100% rename from examples/B04_secure_design/secret_from_env.py rename to examples/B04_secure_design/06_secret_from_env.py diff --git a/examples/C18_sqlite/__init__.py b/examples/C18_sqlite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mkdocs.yml b/mkdocs.yml index afa1eee..3c30b22 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -30,10 +30,10 @@ nav: # - Dunder Methods: A15_dunder_methods.md # - Lambda Functions: A16_lambda_functions.md # - Generators: A17_generators.md -# - Metaclasses: A18_meta_classes.md +# - Coroutines: A18_coroutines.md # - Comprehensions: A19_comprehensions.md -# - Data Handling: A23_data_handling.md # - Type Hints: A20_type_hints.md +# - Metaclasses: A21_meta_classes.md - Design: - OOP Basics: B01_oop_pillars.md @@ -43,5 +43,8 @@ nav: - Libraries: - Logging: C01_logging.md + - Threading: C02_threading.md + - Miltiprocessing: C03_multiprocessing.md + - concurrent: C04_concurrent.md - Serialization: C12_serialization.md - Data Structures: C13_data_structures.md