Giter Club home page Giter Club logo

python-head-first-design-patterns's Introduction

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 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
           }

python-head-first-design-patterns's People

Contributors

rebuild-123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.