2009 May 31 6:04 AM
Hi Experts,
Can I hv a brief answer for the question of Difference between a CLASS and OBJECT?
I tried to interprete my self, but, I culd not able to find out the answer.
thanq
2009 May 31 9:17 AM
Hi,
If you understand difference between a car and a construction project of this car in real world, than you understand the difference between an object and a class in programming model.
Class is simply a type like your basic types ( i, f, p, d, t, n, c ) which you use for typings, when you declare a reference variable (for basic type you use data object ). So there is no functional difference in below two statements:
data: my_data_obj type i.
"and
data: my_ref type ref to lcl_my_class.
You can have one or more data objects of type i in your program and one or more objects (so called instances ) of type lcl_my_class . It is understandable that each data object of type i has some common features (like range of type i ) and has some differences, like different value which it really stores.
The same applies to lcl_my_class . There are some static attributes, which are common to all objects (accessed by my_ref ) and some typical for each of them.
I.e. you have many cars (objects) created from one construction projects (class). Every car has same part (like steering wheel, 4 wheels, a trasmision gear etc) - so these are common to every car, but you still have some differences like color of the car, like windows tint, engine capacity etc.
The way car behaves (accelerates, stops, make turn) is similar to all these cars. This behaviour is called method .
Classes are not tied to particular programming language, they are simply a cast from real world to something more readable to computers, so called abstraction . You can google this topic, there are lots of sites describing the difference in detail. Example [link|http://www.felgall.com/obj1.htm]. Of course what was written here, is just a basics of real powerful object world. I recommend to study some book covering this topic like [ABAP Objects: Introduction to Programming SAP Applications|http://www.amazon.co.uk/ABAP-Objects-Introduction-Programming-Applications/dp/0201750805]
or simply read some [SAP documentation|http://help.sap.com/saphelp_nw70/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm] as far as you want to consider object related programming in ABAP terms.
Regards
Marcin
2009 May 31 6:39 AM
Hi,
A class is an object oriented concept that has methods in it,
Methods can be of Public-accessible outside, Private-Onlywith in the class and Protected
A class can have inheritance and all the Object oriented properties in it...
An object is an instance of the class, To access a class within the program/FM, you need to instantiate the class, Hence an Object is used to instantiate the class...
Regards
Shiva
2009 May 31 6:46 AM
Hi,
Class is a prototype that defines data and the behaviour common to all the objects of certain kind. Here methods provide the behaviour. We can say classes describe objects.
Classes can be declared either globally or locally. Global classes can be declared using transaction SE24. Local classes are declared in an ABAP program (reports etc).
Object:
It signifies the real world. Technically we can say objects are instances of a class. We can create any number of objects from a class template. All the objects created have unique identity and each contain different set of attributes. Objects we create in a program exist only till the program exists.
Regards
Shiva
2009 May 31 9:17 AM
Hi,
If you understand difference between a car and a construction project of this car in real world, than you understand the difference between an object and a class in programming model.
Class is simply a type like your basic types ( i, f, p, d, t, n, c ) which you use for typings, when you declare a reference variable (for basic type you use data object ). So there is no functional difference in below two statements:
data: my_data_obj type i.
"and
data: my_ref type ref to lcl_my_class.
You can have one or more data objects of type i in your program and one or more objects (so called instances ) of type lcl_my_class . It is understandable that each data object of type i has some common features (like range of type i ) and has some differences, like different value which it really stores.
The same applies to lcl_my_class . There are some static attributes, which are common to all objects (accessed by my_ref ) and some typical for each of them.
I.e. you have many cars (objects) created from one construction projects (class). Every car has same part (like steering wheel, 4 wheels, a trasmision gear etc) - so these are common to every car, but you still have some differences like color of the car, like windows tint, engine capacity etc.
The way car behaves (accelerates, stops, make turn) is similar to all these cars. This behaviour is called method .
Classes are not tied to particular programming language, they are simply a cast from real world to something more readable to computers, so called abstraction . You can google this topic, there are lots of sites describing the difference in detail. Example [link|http://www.felgall.com/obj1.htm]. Of course what was written here, is just a basics of real powerful object world. I recommend to study some book covering this topic like [ABAP Objects: Introduction to Programming SAP Applications|http://www.amazon.co.uk/ABAP-Objects-Introduction-Programming-Applications/dp/0201750805]
or simply read some [SAP documentation|http://help.sap.com/saphelp_nw70/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm] as far as you want to consider object related programming in ABAP terms.
Regards
Marcin
2009 Jun 01 7:55 AM
Hi,
OBJECT is an entity which can be percevied, having a particular form and it's having certain attributes.
example : CAR, Computer and Watch....
Objects are Resuable , sharable, Maintainable and modifiable.
Classes are templates that describe how the object will look like. You can think of the class-object relation as one similar to internal table-type(structure) statement.
Example :
CLASS my_first_class DEFINITION.
PUBLIC SECTION.
DATA: one_variable TYPE i.
METHODS i_square.
ENDCLASS. "my_first_class DEFINITION
----
CLASS my_first_class IMPLEMENTATION
----
CLASS my_first_class IMPLEMENTATION.
METHOD i_square.
one_variable = one_variable * one_variable.
WRITE one_variable.
ENDMETHOD. "i_square
ENDCLASS. "my_first_class IMPLEMENTATION
Reg,
Siva Prasad