Skip to content

Python for Head First Design Patterns book (2020)

Notifications You must be signed in to change notification settings

rebuild-123/Python-Head-First-Design-Patterns

Repository files navigation

Python Head First Design Patterns

Don't forget to give this repository a star, thanks.

Chapters

chapter 1(strategy)
chapter 2(observer) (Only swing has no translation.)
chapter 3(decorator) (Only io has no translation.)
chapter 4(factory)
chapter 5(singleton)
chapter 6(command) (Only swing has no translation.)
chapter 7(adapter)
chapter 7(facade)
chapter 8(templatemethod) (applet and frame have no translation.)
chapter 9(iterator)
chapter 9(composite)
chapter 10(state)
chapter 11(proxy) (Translating this chapter is beyond my ability.)
chapter 12(combining)
chapter 12(combined) (Translating this subsection is beyond my ability.)
chapter 13 (No code)
Appendix (bridge)
Appendix (builder)
Appendix (flyweight)
Appendix (prototype)
Appendix (collections)
Appendix (ducks)
Appendix (iterenum)

Introduction

  1. Translated from Head-First-Design-Patterns (java)
  2. What are the differences between other Python version Head-First-Design-Patterns and ours?
    • We named the files with the same name and path as the original. (The following examples are from Chapter 1.)
      image
    • We annotate the type of the code so that the code we translate is closer to the java version. (The following examples is from strategy/AnimalTest.py.)
      # our codefromabcimportABC, abstractmethodfromtypingimportListclassAnimalTest: @staticmethoddefmain(*args): at: AnimalTest=AnimalTest() at.makeSomeAnimals() defmakeSomeAnimals(self): dog: Animal=self.Dog() cat: Animal=self.Cat() # treat dogs and cats as their supertype, Animalanimals: List[Animal] = [] animals.append(dog) animals.append(cat) foranimalinanimals: animal.makeSound() # can call makeSound on any Animal
      // authors' code [https://github.com/bethrobson/Head-First-Design-Patterns/blob/master/src/headfirst/designpatterns/strategy/AnimalTest.java]importjava.util.ArrayList; publicclassAnimalTest { publicstaticvoidmain(String[] args) { AnimalTestat = newAnimalTest(); at.makeSomeAnimals(); } publicvoidmakeSomeAnimals() { Animaldog = newDog(); Animalcat = newCat(); // treat dogs and cats as their supertype, AnimalArrayList<Animal> animals = newArrayList<Animal>(); animals.add(dog); animals.add(cat); animals.forEach(Animal::makeSound); // can call makeSound on any Animal }

Releases

No releases published

Packages

No packages published

Languages

close