I was reading “Design Patterns: Elements of Reusable Object-Oriented Software“, (specifically the chapter about the prototype design pattern) and it stated that…
“Prototype is particularly useful with static languages like C++ where classes are not objects, and little or no type information is available at run-time.” (pg 121)
(emphasis mine)
I had always thought that classes were synonymous to objects, and I’m confused as to what this statement means. How are classes not objects, and why does it matter if a language is static?
In C++, this declares a class:
whereas this declares an object:
One cannot interrogate a class a run-time, as one can interrogate an object. It makes sense to say, “object ‘a’, what is your address? Please invoke
operator+. etc.” In C++, with its static typing, it makes no sense to say, “Class A, what is your list of members? Please add a new member, “b”.”In other languages (Python comes to mind), one can manipulate classes in this way, because each class is also an object. In addition to serving as a template for objects, the class itself is an object — it can be printed, modified, etc.