answersLogoWhite

0


Best Answer

We can think of an object is being an aggregate of one or more data types, where each member is allocated memory according to its type, and one member immediately follows another in the order it is declared. The total size of an object is therefore equal to the sum of its member types. However, some types need to be padded so they begin on a word boundary (such as a 4 byte boundary), so there may be unused padding bytes between certain members. This is why we strive to declare data members in descending order of size to minimise wastage.

Public and protected members are also inherited from base classes and are therefore part of the derived object, however private members are also part of the object (they're simply not accessible via the derived object), thus the total size will include those members as well. As such, each member can be accessed indirectly as an offset from the start address of the object. However, the compiler takes care of this for us, we can simply access object members through their given name (so long as access is permitted of course).

While every object of a class has its own discrete set of member data, as determined by the class definition, there is only one instance of each member function. The compiler knows which instance of the object to operate upon because a hidden "this" pointer is passed to every non-static member function. Thus the member functions are not considered part of the object per se, they are part of the class.

Every class that declares or inherits a virtual function also has its own virtual table, which is an aggregate of its base class virtual tables plus any of its own virtual function declarations. Each entry in the table points to the most-derived override for each virtual function. This ensures that the most-derived override is invoked even when the function is called against one of the object's base classes.

As such, there is only one implementation of every function in a program, and each has a unique address regardless of how many objects that function is a member of. This is similar to the way in which static member functions are shared by all instances of a class, the only difference being that static member functions do not receive a "this" pointer. By the same token, there is only one instance of each static data member which is shared by all objects of the class but is not associated with any specific object of the class. All static data members are allocated in the program's data segment whereas non-static member data is allocated on the stack unless the object is allocated dynamically upon the heap.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Data and functions are placed into some classes (an instance of a class is an object of that class). The classes are the abstraction (of some things) and with inheritance being a part of "being a class", to encapsulate the data and functions operated on those data.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Object Oriented Programming has everything to do with a programming language.

Programming Languages are classified into:

1.Object Oriented Programming

2.Process Oriented Programming

In Object Oriented Programming, more stress is given to data rather than Algorithm of the program giving the programmer his fre will to do anything without violating few rules of programming(like grammatical errors).

Object Oriented Programming breaks the program into small objects so as to make it easily changable & to prevent free flow of data and also to create a logical insulation between the program and outside world.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

It depends on the language implementation. However, in C++, a member function is not actually part of the class in which it is declared. That aspect only exists within the source code and is simply a programming aid to help us reason our code more easily. Once compiled, the object-oriented nature of the source code is completely stripped away; it has served its purpose and is no longer required.

To understand this better, consider the following code:

class foo {

int attribute;

public:

void method (int data) {attribute = data; }

};

int main () {

foo f; f.method (42); }

When we compile this code, the machine code generated by the compiler is essentially the same as the machine code generated by the following C code:

struct foo {

int attribute;

// ...

};

void method (int data, foo* this) { this->attribute = data; }

int main () {

foo f;

method (42, &f);

return 0;

}

With a suitable compiler, it is possible to generate pure C code from C++ code. Indeed, that's precisely how the very first C++ compiler worked!

From this we can see that the actual object's layout is no different to a struct in C. That is, all non-static member data is stored in the class (struct) instances while static member data is allocated in static memory. Hence static member data is accessible without instantiating objects of the class.

Non-static member functions and static member functions are simply treated as if they were global functions. The only difference between the two is that a non-static member function has an implicit "this" pointer while static member functions do not.

Note that we do not need to test the "this" pointer for NULL before dereferencing it; it has to be non-NULL because the original C++ code guaranteed it; the member function was invoked against an object of the class, therefore the object must exist. Although it is possible to create a NULL reference in C++, if we follow best coding practices (using resource handles and references instead of "naked" pointer) then it becomes next to impossible to create one by accident. As such we can eliminate a lot of the runtime checks that prevail in pure C code.

Virtual functions are also treated as if they were really global functions. The only difference is that additional memory is set aside for the class virtual table (vtable), which simply holds pointers to the class functions. Each class that declares or overrides a class with virtual functions has its own virtual table with its own set of function pointers. When we implicitly invoke a virtual function, the compiler generates code to perform a runtime lookup of the most-derived class vtable in the hierarchy, because its vtable will refer to the most-derived override. This incurs a small performance overhead but the lookup is much quicker than using runtime type information. Conversely, if we explicitly invoke a virtual method against a particular class within the hierarchy, then the compiler simply looks at the virtual table specific to that class and statically binds to the appropriate function at compile time. As such, a derived class can override its base class and (optionally) explicitly invoke its base class method at no additional cost.

This answer is:
User Avatar

User Avatar

Vincent Mutai

Lvl 2
2y ago

How are data and functions organised in an object oriented program?

This answer is:
User Avatar
User Avatar

Elinor Murray

Lvl 1
2y ago
where did you find your answer

User Avatar

Wiki User

14y ago

Data and methods in OOP are organized in classes.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

dfdafdaf

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How the data and functions are organized in object oriented programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is full form of oop's?

Object Oriented Programming


Is PHP object oriented?

Yes - 'advanced' PHP programming uses Object Oriented Programming (OOP).


What is an essential of Object Oriented Programming?

The 3 essential concepts of Object Oriented Programming are:InheritanceEncapsulation &Polymorphism


What is the distinct difference between object oriented concept and object oriented programming?

Object oriented concepts are a generalisation of the object oriented principals (encapsulation, inheritance, polymorphism and abstraction) without specifying a particular implementation of those principals. Object oriented programming is the application of those principals through an object oriented programming language.


Is c is complete object oriented programming language?

No. C is not object oriented. C++ is object oriented.


Full form of oops?

The full form of OOP is Object-Oriented Programming.


What is the difference between a class method and object in object-oriented C?

Class methods are the member functions that act upon member variables. An object is an instance of a class. C does not support object-oriented programming, but C++ does.


What is difference between Function Oriented Design and Obeject Oriented design?

In function oriented design a problem is thought in form of data and functions to manipulate those data. Both entities remain independent of each other. On the other hand in object oriented design a problem is thought in form of an encapsulated entity where both data and functions stay together in form of an object. Following link has a nice collection of articles of object oriented programming: http://cs-fundamentals.com/java-programming/java-programming-tutorials.php


What actually mean by object oriented programming Is C plus plus is a object oriented programming?

Just eat a watermellon!


Define structure oriented programming language?

A structure oriented language is one, which should the following structure as Documentation Section, Link section, Definition Section, Global declaration section and Functions(including Main functions) in an hierarchical order. This order cannot be interchanged, but structure oriented language like C can have these sections as optional. Correct me if am wrong, Neela.T


What are the limitation of structured programming?

By itself, structured programming does not support the notion of a function call. This is achieved through an extension of structured programming known as procedural programming. Object-oriented programming extends procedural programming such that data and the functions that operate upon the data can be encapsulated within an object.


What has the author Edmund W Faison written?

Edmund W. Faison has written: 'Borland C [plus plus] 4 object-oriented programming' 'Borland C++ 3 object-oriented programming' -- subject(s): Borland C++, C++ (Computer program language), Object-oriented programming (Computer science) 'BorlandC[plus plus] 4.5 object-oriented programming' -- subject(s): Borland C., C., Object-oriented programming (Computer science) 'Borland C++ 3.1 object-oriented programming' -- subject(s): Borland C++, C++ (Computer program language), Object-oriented programming (Computer science)