jsteinberg4 / design_patterns

Repo to contain code where I practice implementing software design patterns. Patterns may be implemented through toy examples or practical applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

design_patterns

A repo to contain code where I practice implementing software design patterns. My practice started in python with the python/ folder. Any additional languages will get their own dedicated folder following the same naming convention (ex: Java examples in the directory java/).

Table of Contents

  1. Proxy Pattern

Proxy Pattern

Pattern Overview
  • The proxy pattern is a structural design pattern which adds a hidden abstraction layer between client code and implementations of necessary program logic.
  • The goal of the proxy pattern is to not change the user experience of interacting directly with "business logic" classes, despite injecting a middle-man.
Applications
  • Suppose you have a class which conducts CRUD (Create, Read, Update, Delete) operations. It might initially make sense for this class to maintain a persistent connection to some database. This is not inherently wrong; however, connecting to database (especially in a production environment) is often slow. Maintaining a persistent connection will also tie up valuable network bandwidth for the database host. It would be better to delay opening a connection until absolutely necessary.
  • By inserting a proxy class layer in between a user and this CRUD class, you could add logic for delaying a database connection, implementing access control restrictions, caching/batched operations, or anything else. If the design is implemented properly, the user experience will be functionally identical to interacting directly with the CRUD class.
Example Code
  • Implemented in python:
    • Toy example in python/src/proxy_pattern
  • Implemented in Java:
    • Toy example in java/src/proxy_pattern

About

Repo to contain code where I practice implementing software design patterns. Patterns may be implemented through toy examples or practical applications.

License:MIT License


Languages

Language:Python 63.3%Language:Java 36.7%