Oliver Nassar

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar

Instantiable classes versus static classes

View more posts

In creating my JS Type Hinter, I ran into a semantic issue as to whether or not the class I was creating should be instantiable or static. I thought about it, and break down this decision using the following criteria.

By no stretch are these finite rules, but they're generally what I try to follow.
The Type Hinter for example is a static class. My rationale for that was:

It just didn't make sense. On the other hand, my Node Mongo Wrapper, which is currently static, ought to be instantiable. It is resource-based (eg. the db it's connecting to; perhaps even the collection it's querying against); and one instance of the class could be used reliably per page load.

That's on the list, but this is the general guideline I follow when decided between static and instantiable class definitions.