rebuild-123/Python-Head-First-Design-Patterns
关于
《Head First Design Patterns》(2020)一书的 Python 实现
学习与教育实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文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
- Translated from Head-First-Design-Patterns (java)
- 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.)
- 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 code from abc import ABC, abstractmethod from typing import List class AnimalTest: @staticmethod def main(*args): at: AnimalTest = AnimalTest() at.makeSomeAnimals() def makeSomeAnimals(self): dog: Animal = self.Dog() cat: Animal = self.Cat() # treat dogs and cats as their supertype, Animal animals: List[Animal] = [] animals.append(dog) animals.append(cat) for animal in animals: 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] import java.util.ArrayList; public class AnimalTest { public static void main(String[] args) { AnimalTest at = new AnimalTest(); at.makeSomeAnimals(); } public void makeSomeAnimals() { Animal dog = new Dog(); Animal cat = new Cat(); // treat dogs and cats as their supertype, Animal ArrayList<Animal> animals = new ArrayList<Animal>(); animals.add(dog); animals.add(cat); animals.forEach(Animal::makeSound); // can call makeSound on any Animal }
- We named the files with the same name and path as the original. (The following examples are from Chapter 1.)
探索相关项目
加载中…