What's the best way to define the words "class" and "object" to someone who hasn't used them?

34,230

Solution 1

A class and some class instances:

Courtesy of wikipedia

(public domain image hosted by wikipedia)

Solution 2

Class : Object :: Blueprint : Building

Solution 3

"Car" is a class. My car, sitting in my driveway, is an instance (object).

Solution 4

One of the examples I use during my java courses is the Human class.

Everyone reading this is a Human (I least I hope so !), we all have our differences our resemblances but at the end we're all Human (After all).

Each Human (known as an instance or object) has specific characteristics such as the eyes color or the voice which are the fields (you called that variables, but the right name would be fields). But the values are different from an Human instance to another.

There is also a common knowledge, shared with the humanity, principles like the "Pythagorean theorem". This knowledge is common, it can be interpreted as a static field (I know it's an exaggeration) which means that this knowledge is not only contained in one human but in the humanity.

Every Human can do things such as walking, speaking etc. this is known as method, walking is the same for everyone, but when I walk, not everyone walk. The act of walking only affects the Human instance which does this, but still it's defined by the Human class


If you want to get deeper in OOP, Teaching OOP to non-programmers

Solution 5

An object is a thing. A class is a category of things.

"Person" is a class; you are an object, an instance of the Person class. Also, the word "you" can be thought of as a variable, since it refers to a Person, but not always the same Person.

Share:
34,230
Dean J
Author by

Dean J

I like working with good people, building interesting things, and pulling up others to do more. I generally lead small offices or mid-size organizations. I’m an engineer (PHP/Java/C++/Python/JS/C#/etc). I’ve driven major increases in revenue, while simultaneously improving user quality. I have experience in technical design, process improvement, team leadership, user experiments, and data analysis. I’ve interviewed hundreds of people and worked in multiple roles with hire/fire responsibilities. Extensive K-12 outreach, work as a teaching assistant, and an awful lot of patents. Prior to technology, I worked as a cab driver, concert promoter, and bartender. If there was a course that computer science degrees lack that was designed to make you a much better engineer early-career, even odds that The Pragmatic Programmer and Code Complete would be the texts. As the less-technical guide to working in the software industry, Team Geek is worth a read. (Or it's second version, Debugging Teams.) For interviews specifically, Steve Yegge made a post that got me my job, and I wrote a later article talking about technical interviews aimed at undergrads. Gayle McDowell's set of books are the full length master class. Meanwhile, some of my responses on stackoverflow: What should a developer know about UI design? Pitfalls when outsourcing? Why is a data structures course important? When should you break away from xxxx to improve performance? Why isn't the Referral Removed for HTTPS -> HTTP? Meta: in the comments, showing someone how to ask questions

Updated on July 09, 2022

Comments

  • Dean J
    Dean J almost 2 years

    My neighbor is taking "Intro to Java", and asked me to help explain a few of the first-day concepts. I realized that since I do this everyday, I don't have the beginner's mind, and it's hard to relate some of this stuff from scratch.

    The one that's actually not trivial for me to explain is "what the heck is a class?"


    Best I have so far:

    • A variable holds some kind of data; one variable might be a first name, another variable might be your weight in pounds.

    • A method is a function, it does stuff, and can do stuff with those variables. A method might display your name on screen, or tell you how much weight you should lose to have a good BMI ratio.

    • An object holds both variables and methods; one object might represent you, a second object might represent me.

    • A class is kind of the blueprint or template that describes the methods and variables that will be in each object. An object is an instantiated (instance of a) class; an object is something, while the class is simply the plans to make that something.

    Continuing the example, we have a Person object, which is instantiated to hold Alice's data, and another Person object instantiated to hold Bob's data, and another for Carol, and so on.


    How do I tune this example to make more sense, and/or what's a better approach? The word "instantiated" feels too heavy at this point.

    (I think this is a useful question, but is obviously subjective; marked as community wiki.)