These are my reading notes for Code Fellows
Explain what a “Singleton” is (in Computer Science terms)
A Singleton is a design pattern “…that restricts the instantiation of a class to one “single” instance. This is useful when exactly one object is needed to coordinate actions across the system. The term comes from the mathematical concept of a singleton.” (source)
“Design patterns are reusable, reliable solutions to problems that we face every day in software development.” (source)
Explain how the Singleton pattern can be used with Node modules, specifically with classes
(source)
“Modules are cached after the first time they are loaded. This means (among other things) that every call to require(‘foo’) will get exactly the same object returned, if it would resolve to the same file.”(source)
If you were tasked with building a middleware system like Express uses, what approach might you take to construct/operate it?
If it were up to me, I’d be a bit more specific, or at least more clear, about what next()
targets. That is, which step is next in the next()
cycle. I suppose I would create middleware like we’ve been doing in lab, checking if a condition is met/satisfied, then telling the code to move on to the next file in the hierarchy.
“Express middleware are functions that execute during the lifecycle of a request to the Express server. Each middleware has access to the HTTP request and response for each route (or path) it’s attached to” (source)
“a mechanism by which a computer program can, at run time, load a library (or other binary) into memory, retrieve the addresses of functions and variables contained in the library, execute those functions or access those variables, and unload the library from memory.” (source)
A singleton represents a single instance of an object. Only one can be created, no matter how many times the object is instantiated. If there’s already an instance, the singleton will create a new one.” (source)
“A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.”(source)