- A singleton is a class that allows only a single instance of itself to be created and gives access to that created instance. It contains static variables that can accommodate unique and private instances of itself.
- The singleton pattern is used in programming languages such as Java and
classical singleton is actually return that instance using a get instance method. And what we can do within this method is return our singleton instance. There we go. So this class only allows us to instantiate one logger and then using the get instance method we can return that logger to any file that wants to use it.
If you were tasked with building a middleware system like Express uses, what approach might you take to construct/operate it?
Okta has an Express middleware for OIDC security that I’ll show you to demonstrate using third-party middleware libraries.
-
Router Middleware : . It is a piece of code that comes in the middle of request and response .
-
Dynamic Module Loading : load a library (or other binary) into memory
-
Singleton Pattern : used to provide global point of access to the object
-
CRUD -> REST Method Matches : Create = PUT with a new URI POST to a base URI returning a newly created URI Read = GET Update = PUT with an existing URI Delete = DELETE
-
Mock Testing : Mocking is useful to validate such calls without the side effects. Mocking avoids duplicating test code across similar tests.
- Which 3 things had you heard about previously and now have better clarity on?
- Router Middleware and how to use it
- how Singleton Pattern work
- how Dynamic Module Loading work
- Which 3 things are you hoping to learn more about in the upcoming lecture/demo?
- authorization in middleware
- pattern in codes
- mocking in app
-
What are you most excited about trying to implement or see how it works?
-
making my private Singleton Pattern