Tag Archives: design patterns

Building your own API and Securing it with oAuth 2.0 in ASP.NET WebAPI 2


  1. Make a true RESTful Web API (enable CRUD functions by HTTP POST, GET, PUT, and DELETE).
  2. Enable Cross-Origin Resource Sharing, i.e., CORS (the accessibility of the API by JavaScript can be controlled).
  3. Enable Secure Authorization for API calls (use the OAuth 2.0 authorization framework).
  4. Enable Transport Layer Security, i.e., SSL (reject every non-HTTPS request).

Continue reading

A Simple AS3 Logging Library using the Chain Of Responsibility and Singleton Pattern

Few years back, I wrote a simple logging library in ActionScript3 using the Chain of Responsibility pattern. Recently, I dug up the old codes, made some modifications, and put it in github for other people to use and contribute. In this post, I will mainly focus on how to use the library and do some project specific modifications, but  I will also briefly discuss my reasons for using the Chain Of Responsibility and the Singleton Pattern. I started writing this library with the following 4 goals in mind:

  1. It should be easily accessible to all of the classes of a project.
  2. It should be able to write logging information to different output sources, i.e., file, database, console, etc., and additional output sources can be added easily.
  3. It should be able to handle different levels of logging like FATAL_ERROR or INFO (as different actions may be needed for handling different levels), and additional levels can be added easily.
  4. It should require minimal setup.

Continue reading

Is Singleton Root of All Evil?


Despite all its criticism, singletons still exists today, perhaps because insecure programmers feel the illusion of doing the “right” thing, since they are after all using a design pattern. For those who think, “What experts do, must be right”, I will leave a famous quote by Christopher Hitchens-

Picture all experts as if they were mammals. … Seek out argument and disputation for their own sake.

The popularity of the word ‘singleton’ probably comes from set theory, where it is a set with exactly one element. Similar to its mathematical counterpart, a singleton pattern in software engineering ensures exactly one instance of a class for each running application. This is how you would write a singleton class in Java: Continue reading