oops

4
class : class is a user defined data type which is a collection of different type of components ( attributes, methods,events,interfaces,aliases) why use class- data is secure because it uses access specifiers which control the visibility of class component. public section protected section private section it supports the dynamic capability in nature. means- encapsulation inheritance pollymorphism data abstraction public section - can be inherited to subclass . can be accessed directly outside the class. protected section- can be inherited to subclass. can't be accessed outside the class. private- cant be inherited. cant be accessed outside the class. ** attributes- used for storing the properties of class. instance attribute,static attribute instance attribute- these are specific to object. for every instance attribute separate memory will be allocated for each and every object. keyword - DATA

Upload: shreeram-sahu

Post on 13-Apr-2016

5 views

Category:

Documents


0 download

DESCRIPTION

Oops

TRANSCRIPT

Page 1: Oops

class : class is a user defined data type which is a collection of different type of components ( attributes, methods,events,interfaces,aliases)

why use class-

data is secure because it uses access specifiers which control the visibility of class component.

public section

protected section

private section

it supports the dynamic capability in nature.

means- encapsulation

inheritance

pollymorphism

data abstraction

public section - can be inherited to subclass .

can be accessed directly outside the class.

protected section- can be inherited to subclass.

can't be accessed outside the class.

private- cant be inherited.

cant be accessed outside the class.

** attributes-

used for storing the properties of class.

instance attribute,static attribute

instance attribute- these are specific to object. for every instance attribute separate memory will be allocated for each and every object.

keyword - DATA

static attribute- they are not specific to object. the memory for these attributes will be allocated only once when ever the first object is created and rest of the object will point to the same memory location.

keyword - CLASS-DATA.

Page 2: Oops

if we want to maintain diff value for each object then we use instance attribute and if we want to maintain same value for every object then we use static attribute.

***method-

is a set of statement which is defined only once and can be called any no of times.

instance method and static method.

instance method- declared by keyword 'METHOD'.

these method can access both instance and static attribute.

they can be accessed only by using objects.

static method - declared by ' CLASS-METHOD'.

they can access only static attributes.

syntax-

declare the method in class defination.

implement the method in class implementation.

method< method name>.

statement.

end method.

calling the method

call method <method name>

parameter list.

*** exception handling in method-

exception is a run time error which is raised during program execution. if the exception is not handled the program will be terminated.

exception handling is a process of handling run time error and continuing the program execution without termination.

TRY AND CATCH BLOCK.

as part of try block we need to keep those statement where the possible exception might occure.

in catch block we need to handle the exception by writting the exception handling statement.

class abc implementation.

method m1.

Page 3: Oops

try.

z=x/y.

catch cx_root. ( exception class name which is responsible for raising the exception)

message.

endtry.

endmethod.

***inheritance-

it is a process of acquiring the properties of other class.

the class which gives the proprties is called as super class and the class which takes the proprtes is called sub class.

class abc defination inheriting from class pqr.

class pqr- super class

class abc - sub class

when we inherit the component the visibility of the component cant be changed.

** interface--

it is a pure abstract class. by default all the methods of interface are abstract and public.

the class which ever is implementing the interface is called as implementation class.

interfaces are always implemented in public section.

is we are implementing interface methods inside a class then we have to implement all the methods otherwise it will be treated as abstract class.

**event--

sap has provided many standard events which are raised by sap itself. as a developer we need to handle it.

events are used for providing dynamic features to the application which involves classes and objects.

raise the event in one of the method implementation-

raise event <event name>

expoeting parameter.

register the handler.

Page 4: Oops

set handler <handler> for <instance>.

every event can contain one or more event handler method.

when ever the event is raised sap execute all the event handler method one after other by using handler registration.

the sequence of execution of event handler method depend upon the sequence of handler registration.