Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I came across the analogy of the class being a cookie cutter and the cookies being objects while reading Code Complete. I fail to see why this analogy was drawn.How is it related to the concept of objects being run time instances of their classes?

share|improve this question
A cookie cutter defines the shape and size of cookies. A class defines its objects. – Yannis Mar 2 '13 at 15:40
As Yannis says, the class describes the "shape", while the object is an actual thing you created from it. That said it's (my humble opinion) one of the worst and most misleading ways to describe OO concepts. – thorsten müller Mar 2 '13 at 15:47
@thorstenmüller yes I share the same feelings .This is why I posted this question. – Geek Mar 2 '13 at 15:52
up vote 4 down vote accepted

The analogy is a bad one, because it can convey the essence of classes and objects if you apply the right mental mapping, but that mapping is not obvious to arrive at, and perhaps not even the most convincing one.

A class is like a cookie-cutter in that it has the power to create multiple items that are alike in some ways: they all have the same number and type of fields, while their values can differ. You can compare this to all cookies having the same shape, but it is unclear how the differences between individual cookies map to the differences between objects that are class-mates; in my mind, two Cartesian coordinates with different X and Y values are much more different than similar, certainly much less alike than two cookies with the same shape.

share|improve this answer
Still, two Cartesian coordinates are much more similar then a Cartesian coordinate and a cookie. Bad analogy is good enough. – scrwtp Mar 2 '13 at 20:45
It's not a good analogy because the cookie cutter is as physical of an item as the cookies it produces. I prefer to compare a class to a dictionary entry- it is more conceptual and tells you what a cookie is through text. The actual cookies would comply with the definition that is given. – Chris C Mar 4 '13 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.