Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What is the difference between class and object?

Status
Not open for further replies.

ansh11

Member level 4
Joined
Feb 27, 2018
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
659
What is difference between class and object

I'm slightly confused between object and class in programming language. I looked some tutorials but still getting confused.

This is example that I want to understand regarding class and object

Code:
class person
{
  public:
    string name;
    int age;
};

I m confused can anyone explain what the example you prefer to understand difference between object and class in programming
 

Re: What is difference between class and object

The code you mentioned is a class. An object is created from an class and it will be an instance. So, you can create many instances of the class that is many objects can be created. For eg,. In Windows Explorer is an object and it is derived from a class and you can open many instances of Explorer.
 

Re: What is difference between class and object

A class defines the properties of the object that will be created from a class. Object instance or instance of an object has to be created before using them.
 

Re: What is difference between class and object

Class is a description of something, like an architect's plans and an object is like a house described by those plans. In software creating an object means using the 'new' keyword. If you haven't used 'new' you probably haven't created an object.

Understand that software objects, like like real objects can have a state, contain information and/or perform a function.

The Person class is a type of 'information only' class that doesn't have any functions. I think of that like a government form. The class defines the empty fields. When a clerk pulls out a blank one and fills it out now its an object and the information (name, age) are contained in that object. It can get passed around your program exactly like a physical form can get passed around an office, modified, filed, sorted, taped onto a box so it's linked to that 'object' etc.

More complicated classes also have functions and I think of them like a tool, say an adjustable wrench. This is an object which contains information (the state of adjustment of its jaws) and has functions (tighten, loosen). One part of your program can create the wrench and adjust its jaws, then pass it to another part of your program to use it.

Good program design for a big program will be divided into objects exactly like an assembly line is (painting machine, cutting machine) and will pass the objects between those steps (the important thing being built as well as order forms etc to control and manage).
 
  • Like
Reactions: d123

    d123

    Points: 2
    Helpful Answer Positive Rating
Re: What is difference between class and object

Hello!

If you haven't used 'new' you probably haven't created an object.

As we are on a microcontroller discussion board, in many cases, there is no dynamic
allocation, therefore you won't use new.

Example: in LCD.cpp, LCD.h, you can have the description of your application's LCD.

Then in the main program, you may have:

Code:
LCD		SysLCD;		//	Allocated at the beginning of the program and exists until the end

void main(void) {
	SysLCD.WriteString("Hello");
}

Dora
 

Re: What is difference between class and object

Class = a pattern that the computer uses to create (instantiate) an object

Class definition = a block of code that specifies (or defines) an object’s appearance and behaviour
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top