From f2ac305bfbabf9e212ada5c199f8998c899e4ebb Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Tue, 15 Mar 2022 22:30:01 -0400 Subject: [PATCH] Update for 15-03-22 22:30 --- tech/algorithms.wiki | 20 ++++++++++++++++++++ tech/prototype.wiki | 8 ++++++++ tech/singleton.wiki | 23 +++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tech/prototype.wiki create mode 100644 tech/singleton.wiki diff --git a/tech/algorithms.wiki b/tech/algorithms.wiki index ce871f8..5f52419 100644 --- a/tech/algorithms.wiki +++ b/tech/algorithms.wiki @@ -58,6 +58,26 @@ Different ways to store and operate on data, with differing efficiency * [[machine_learning|Machine Learning]] * [[neural|Neural Networks]] +== Programming patterns == + +=== Creational === + +* [[singleton]] +* [[prototype]] + +=== Structural === + +=== Behavioral === + +* builder +* factory +* facade +* proxy +* iterator +* observer +* mediator +* state + == Common operations == * [[gcd]] - Find the GCD of two numbers diff --git a/tech/prototype.wiki b/tech/prototype.wiki new file mode 100644 index 0000000..1740c42 --- /dev/null +++ b/tech/prototype.wiki @@ -0,0 +1,8 @@ += Prototype = + +This is a design pattern where we copy an existing object without making the +code dependent on their classes. + +The general idea is sometimes we need an exact clone of an object. We cant copy +the object exactly from the outside, as we dont know the private fields. +Therefore, the object can implement a `clone` method diff --git a/tech/singleton.wiki b/tech/singleton.wiki new file mode 100644 index 0000000..fab9574 --- /dev/null +++ b/tech/singleton.wiki @@ -0,0 +1,23 @@ += Singleton = + +A singleton is a design pattern in which a class has only one instance, and +that instance is globally accessable. This is often important for use in shared +resources, such as a file, database connection, or logging application. + +== Implementation == + +* Make the default constructor private, preventing other objects from using + `new` +* Create a static creation method that acts as a constructor. This method calls + a private constructor and instantiates a static field, which is the + singleton. All further calls return a reference to this cached, static + object. + +== Use case == + +* strict control over global vars +* instance where a single instance of an object is required + +== Cons == + +* Take special care to not instantiate several in a multithreaded enviroment