Skip to content

Instantly share code, notes, and snippets.

@httpJunkie
Last active June 21, 2018 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save httpJunkie/60f212e202a9e450f28e to your computer and use it in GitHub Desktop.
Save httpJunkie/60f212e202a9e450f28e to your computer and use it in GitHub Desktop.
Programming Patterns in JavaScript Vs C#

Programming Patterns

This document will serve as a reference for using patterns in JavaScript and C#, initially I will just be defining the pattern as I know and have researched and then a JS vs C# example.

Design Patterns: Elements of Reusable Object-Oriented Software http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=tmm_hrd_swatch_0?_encoding=UTF8&qid=&sr=

http://www.amazon.com/Pattern-Language-Buildings-Construction-Environmental/dp/0195019199 A Pattern Language: Towns, Buildings, Construction (Center for Environmental Structure)

Patterns

Creational

###(New instances and object, creationism)

Explain fully the idea behind this category of patterns, why we place them in this category, what we should be thinking about when we want to use this category.

Constructor

  • Think C#/Java constructors. Gives us the ability to create something, set defaults, do pre and post creation tasks. BTW in JavaScript the constructor exists, but we will need to do things slightly different.

Module

http://www.c-sharpcorner.com/UploadFile/5d932c/javascript-factory-pattern/

  • Extracted and enclosed Group of like methods or a service.

Factory

  • Factory: A factory that creates objects that derive from a particular base class.
  • Abstract factory: A factory that creates other factories, and these factories in turn create objects derived from base classes. You do this because you often don't just want to create a single object (as with Factory method) - rather, you want to create a collection of related objects.

Singleton

http://robdodson.me/javascript-design-patterns-singleton/

  • Ensure a class has only one instance and provide a global point of access to it.
  • The Singleton Pattern limits the number of instances of a particular object to just one. This single instance is called the singleton. Singletons are useful in situations where system-wide actions need to be coordinated from a single central place. Singletons reduce the need for global variables which is particularly important in JavaScript because it limits namespace pollution and associated risk of name collisions. The Module pattern (see our JavaScript + jQuery Design Pattern Framework) is JavaScript's manifestation of the Singleton pattern.

Several other patterns, such as, Factory, Prototype, and Façade are frequently implemented as Singletons when only one instance is needed.

Structural

###(Definition at a glance) Explain fully the idea behind this category of patterns, why we place them in this category, what we should be thinking about when we want to use this category and why it matters in the wholae damn thing of things, this text needs to be Replaced ok

Decorator

Facade

Flyweight

Behavioral

###(Definition at a glance) Explain fully the idea behind this category of patterns, why we place them in this category, what we should be thinking about when we want to use this category and why it matters in the wholae damn thing of things, this text needs to be Replaced ok

Command

Mediator

Observer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment