Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

class and interface

Former Member
0 Likes
1,223

Hi All

what is the difference between class and interface.

what is the meaning of below statement.

'compared to interfaces, abstract classes can be partly implemented but restricted by single inheritance'.

And i need notes on how to handle different events in OOABAP with examples.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,152
9 REPLIES 9
Read only

Former Member
0 Likes
1,153
Read only

former_member69765
Contributor
0 Likes
1,152

Unlike C++ Multiple inheritance is not allowed in ABAP and JAVA ..

So handle such situations where multiple inheritance is required ABAP has come up with a concept called Interface. Interface is just a class that has only definition/declaration and has not been implemented. It is like an abstract class... Interfaces are implemented in classes.

Abstract classes can be inherited only once while using interfaces we can have multiple inheritance.

Hope this was helpful..

Read only

0 Likes
1,152

Hi varun,

can we create components (events,methods,types...etc ) for interface in class builder.

If we can , tell me the situation where we use classes and interfaces.

Read only

0 Likes
1,152

In ABAP Objects, the same components (attributes, methods, constants, types, alias names) can be defined in an interface in largely the same way as in classes. However, interfaces do not have component visibility sections.

Interfaces are implemented in classes.

The interface name is listed in the definition part of the class. Interfaces can only be implemented ‘publicly’ and are therefore always in the PUBLIC SECTION (this is only valid as of Release 4.6).

When to use Class and when interface largely depends on the design part.

these things are not simple.. you need to read in much detail to have a good understanding... give me ur mail Id.. I will mail you a document about OO ABAP.

I hope I am able to explain you what u asked for...

Plz reward points if it was helpful...

Read only

0 Likes
1,151

hi varun,

thanks a lot.

you said only valid as of Release 4.6.

what about from 4.7 onwards........

Read only

0 Likes
1,151

Hi, have a look at this example, it explains the usage of interfaces:

http://help.sap.com/saphelp_erp2004/helpdata/en/48/4aad83b75211d194f50000e8353423/content.htm

Read only

Former Member
0 Likes
1,151

This is fundamentals of OO, I would suggest reading some OO basics book. I would suggest read Thinking in Java's 3-4 chapters. This is a free download from www.mindview.net.

hith

Sunil Achyut

Read only

Former Member
0 Likes
1,151

Hi Venkat,

Interface forms the external point of contact for the class and it will not have an implementation part.

Taking a simple example:

Consider a car. The steering, clutch,accelerator, brake forms the interface through which you can control the working of the car,though you don't know what is actually happening inside the car.

All the public components of the class can be included in the interface. The implementation part will be done in the implementing class.

You can go through the below document for knowing the syntax for using interfaces.

http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

You can also create interfaces in the class builder also. You can refer this document for more details.

http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt

<b>Award points if found useful.</b>

Regards,

SP.

Read only

prasanthi_chavala
Active Contributor
0 Likes
1,151

Hai,

Firstly,a clear explanation that as we knw interface is only a collection of methods where as a class is something that holds methods with implementation.

Interfaces enable you to provide your very own functionality for each and every method accordingly and where as an abstract class is a class which has certain non-implemented methods apart from some implemented methods.

-->Abstract class defines few or none of the methods, but interface defines all the methods.

--->Abstract classes should have subclasses else that will be useless..

Interfaces must have implementations by other classes else that will be useless

--->only an interface can extend another interface, but any class can extend an abstract class.

--->All variable in interfaces are final by default

--->If you are declaring a method as a abstact in a class then that class should be declared as an

abstract class class_name

--->An abstract class can have abstract methods as well as concrete methods.

--->An abstract class should have atleast one sub class and in that class all the mthods should implement.

--->An interface should be declared by using the keyword called interface.

--->An interface may (or) may not have sub class implementation.

--->In an interface all the methods are concrete only.

Cheers,

Prasanthi.

        • Reward if helpful