Sie sind auf Seite 1von 4

Implementation Aspects:

 EVERY programming language an implementation model.


 Which MEANS it contains its own specific features.
 But for OOL common ground between them

1. Objects which we know can invoke an instance of a class

2. Classes: Which we know is essentially a blueprint. Defines a set of


properties & methods that are common to all objects of one’s type.

WHICH BRINGS US TO: Inheritance

 A feature that allows new objects to be defined from existing ones.


 ONLY talking about CLASS inheritance

Class inheritance it’s a mechanism for code sharing. (when a class uses code constructed
within another class.)

Interface inheritance is more when an object can be used in place of another.

*PICTURE:
 Straight out of the book
 Shows simple implementation of inheritance
 By class hierarchy using linked list.
 The elements are linked from the subclass to its immediate superclass
(parent class)
 Each element represents a class, the pointers are highlighting the
different implementation of the methods that defined or redefined in
that class.

The inheritance concept is used in many programming languages, LIKE: C++,


Java, PHP, C#, and Visual Basic.
1. C++ uses the ":" operator
2. Java and PHP use the "extend" keyword
3. Visual Basic uses the keyword "inherits."

SLIDE:
Java and C# enable single inheritance only
C++ support multiple inheritance.

Single inheritance:
 only allows one class to be derived from the base class.

PICTURE:
1. B is a subclass of A,
2. B’s vtable contains a copy of A’s vtable and redefined methods are
appropriately modified.
3. The method invocation costs only two indirect accesses.
4. IT comes to show that it is possible to access an object with a
reference that belongs statically to one of its super classes.
Multiple inheritance:
DEFINITION: Multiple inheritance is when a class can inherit attributes and
methods from more than one parent class.
 This can allow programs have more complex relations,
 but it can also introduce a lot of confusion when two base classes
implement a method with the same name.

In EXAMPLE:
Coral_reef is child class inherits from a Coral class and
a Sea_anemone class.
We can create a method in each and then use the pass keyword in
the Coral_reef child class:

The object great_barrier is assigned to CoralReef object, and now can use the
methods in both parent classes.

The fragile base class problem:


 Architectural problem of OOP
 Where super class is considered “fragile”
 Any changes made to super class even small changes, may cause the
subclasses classes to malfunction.
 The programmer cannot know whether a super class change is safe just
by looking at it separately from its sub classes

Dynamic Method:

How JVM help java resolve an overridden method at runtime.


 The compilation of each class in your programs will produce a file which
the JVM loads when the program that is being currently executed refers
to the class.
 This file you can refer to as a constant pool contains:
everything necessary for our program’s execution.
EXAMPLE:
1. method references (#Methodref)
2. Class objects (#Class)
3. String literals (#String)

&& with each variable and method name comes recorded information including the
class where the names are defined and their type.

Every time that the source code uses the name, the intermediate code of the
JVM looks up the index(by IDX to save space) of that name in the constant pool

Execution happens when reference is made to a name for the first time by
INDEX. JVM loads up the necessary classes in which that name is introduced,
visibility checks, type checks are performed. Then JVM saves a pointer to this
info. So, the next time same name is used. Don't have to perform all the
checks again.

Das könnte Ihnen auch gefallen