Class, object, instance and attribute definition

  • Thread starter Thread starter lavster
  • Start date Start date
  • Tags Tags
    Class Definition
Click For Summary

Discussion Overview

The discussion revolves around the definitions and distinctions between classes, objects, instances, and attributes in programming. Participants explore these concepts with examples, seeking clarity on their meanings and relationships, particularly in the context of object-oriented programming.

Discussion Character

  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants suggest that a class can be thought of as a type of thing, with "person" as an example of a class and "Jim" as an instance of that class.
  • Others argue that an object can be synonymous with an instance, and that any noun could be considered an object.
  • One participant describes a class as defining a group of data variables and functions, particularly in languages like C, C++, and Java.
  • Another participant proposes that attributes are best understood as data members in a class, with examples such as "Name" and "Age" for a "Person" class.
  • There is a discussion about whether attributes should be considered a type of data or more accurately described as properties of an object.
  • A later reply provides examples of classes and their attributes and methods, illustrating how instances of classes can be created and manipulated.

Areas of Agreement / Disagreement

Participants express varying interpretations of the terms involved, with no clear consensus on the definitions of attributes or the relationship between classes and objects. The discussion remains unresolved regarding the nuances of these concepts.

Contextual Notes

Some definitions and examples provided may depend on specific programming languages or contexts, and there are unresolved distinctions regarding the terminology used for attributes and their classifications.

lavster
Messages
213
Reaction score
0
Hi,

I have what i think must be a really basic question. What is meant by a class, object, instance and attribute in programming? In simple terms (i don't know computing at all). I thought a class was basically something that could be represented as a noun in everyday life, an object is an instance of a class (whatever that means...), and attribute is something that object does a method on...

but then take example of person making a call on a phone... person is a class? or an object? would it be an object if i made my person a specific person, for example Jim? and then the method is making the call. And then attribute is the phone? but would the phone not be an object. or even a class? Does it depend on the context that it is used in?

I am really confused...

Thanks
 
Technology news on Phys.org
lavster said:
Hi,

I have what i think must be a really basic question. What is meant by a class, object, instance and attribute in programming? In simple terms (i don't know computing at all). I thought a class was basically something that could be represented as a noun in everyday life, an object is an instance of a class (whatever that means...), and attribute is something that object does a method on...

but then take example of person making a call on a phone... person is a class? or an object? would it be an object if i made my person a specific person, for example Jim? and then the method is making the call. And then attribute is the phone? but would the phone not be an object. or even a class? Does it depend on the context that it is used in?

I am really confused...

Thanks


A class is a type of thing. An instance would be a specific thing of that type. If we have to use your analogy, "person" could be a class, and an instance of "person" could be "Jim".

"object" can mean the same thing as instance
 
Last edited:
object - a single entity, in a very generic sense. Just about any noun could be considered an object, such as a car or a tree in a racing game. Think of this as a noun.

class - in C, C++, Java, ... , defines a group of data variables and/or functions as part of a common structure. In the case of C or C++, internally it defines the offsets (relative to an actual instance of the class), data type, data size (or function type and parameters) for all of the defined members of that class.

instance - the actual existence in memory of some object, such as a simple data variable, a class, or the actual execution of function. In the case of a function, if the function is recursive and calls itself, then each call to the function is considered a separate instance of that function.

attribute - The type of data, or function. Think of this as an adjective.
 
I would make a slight argument about "attribute" being a "type of data"...

In Object(dis)Oriented and Database context, I usually use "attribute" as the general description for data members in a class. For instance, the class (or table) "Person" could have the attributes "Name", "Rank", and "SerialNumber". Each of those is a specific data type and probably a class unto itself.

This usage seems to be supported by the Java "Attribute" type, but it's kinda hard to tell from the javadoc: http://download.oracle.com/javase/1.4.2/docs/api/javax/naming/directory/Attribute.html
 
Last edited by a moderator:
schip666! said:
I would make a slight argument about "attribute" being a "type of data"...
Not "a type of data", but instead "the type of data", more like an adjective than a noun. For example what are the attributes of a group of people in a database: their gender, age, ... .
 
thanks :)
 
Consider the following objects:
1) banana, apple, strawberry
2) Robert Millikan, Michael Faraday, Lise Meitner

What do the objects in 1) have in common?
They belong to the class Fruit.

What do the objects in 2) have in common?
They belong to the class Person.

--

Every class consists of two things:
1. Attributes
2. Methods


Attributes describe the object. Another word for attributes is properties.
Methods allow you to access or alter the attributes.

--

Example:

Code:
class Person:

      // Attributes
      name
      age
      weight

      // Methods
      setName(x)
      setAge(x)
      talk()
      eat()


Code:
class Fruit:

      // Attributes
      name
      color
      flavor

      // Methods
      setName(x)
      setColor(x)
      setFlavor(x)

Let's create an object myFruit of the class Fruit:
Code:
myFruit = new Fruit()

Let's define the attributes by applying the methods:
Code:
myFruit.setName("apple")
myFruit.setColor("green")
myFruit.setFlavor("sour")

Now, for some reason myFruit may change its color to "red" and its flavor to "sweet".
We use the methods again:
Code:
myFruit.setColor("red")
myFruit.setFlavor("sweet")

Sometimes, we say instance instead of object. Other objects (or instances) of the class Fruit are 'banana' and 'strawberry'.

---

Here are some links on classes and object oriented programming:
http://www.youtube.com/watch?v=c5kfCH50wl0"
http://www.youtube.com/watch?v=IBpZBI_8QAE&feature=youtu.be"
http://www.youtube.com/watch?v=tUu9V1lAaLM&feature=youtu.be"
http://learntofish.wordpress.com/2009/09/20/object-oriented-programming-an-introduction/"
 
Last edited by a moderator:

Similar threads

  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 25 ·
Replies
25
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
4K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
5K
  • · Replies 3 ·
Replies
3
Views
1K