Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Has anyone got a really good analogy or simple explanation for what a 'class' is?
I'm referring to this PHP video, but I've got a feeling I came across it in Rails too..
Randy describes it in this video but I can't quite wrap my head around it. Can anyone help me out with an alternative description?
Andrew McCormick17,730 Points
Kind of the cliche example but suppose you are building houses, a class is like starting with a blueprint. If you decide to have both three- and four-bedroom houses, you can start with a blueprint (aka a class) called the house blueprint that has a ground floor and a second floor, but has no indoor walls drawn on the second floor. Then, you make two more secondfloor blueprints — one for the three-bedroom house and another for the fourbedroom house. (You name these new blueprints the three-bedroom house blueprint and the four-bedroom house blueprint.) So these other blueprints called 'three-bedroom' and 'four-bedroom' only describe the second floor, because they reference back to (or extend) the house blueprint which contains the info for the ground floor and the exterior of the second floor. So now rather than recreating all the directions for building the initial structure of a house, you can use your class (aka blueprint) to create many houses from one set of instructions.
*partially taken from Java For Dummies