Docsity

OOP - Mod 4 - Realization, Lecture notes of Programming Paradigms

Toggle sidebar
bg1
Mod 4
Realization, Interfaces and Abstract Classes
Realization
➢ a relationship between two model elements, in which one model element realizes
the behavior that the other model element specifies.
➢ one entity denotes some responsibility which is not implemented by itself and the
other entity that implements them. This relationship is mostly found in the case of
interfaces.
Interfaces
➢ a group of related methods with empty bodies
• Abstract – by default, methods are in the form of an unimplemented
function signature
→ An interface can be implemented by a class
→ it is inherited using the keyword, implements.
→ All methods of an interface must be mandatory implemented on all classes
implementing a specific interface.
→ Don’t have an attribute
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download OOP - Mod 4 - Realization and more Lecture notes Programming Paradigms in PDF only on Docsity!

Mod 4

Realization, Interfaces and Abstract Classes

Realization ➢ a relationship between two model elements, in which one model element realizes the behavior that the other model element specifies. ➢ one entity denotes some responsibility which is not implemented by itself and the other entity that implements them. This relationship is mostly found in the case of interfaces. Interfaces ➢ a group of related methods with empty bodies

  • Abstract – by default, methods are in the form of an unimplemented function signature → An interface can be implemented by a class → it is inherited using the keyword, implements. → All methods of an interface must be mandatory implemented on all classes implementing a specific interface. → Don’t have an attribute

Abstract Classes → Have an attribute ➢ If a class includes abstract methods, then the class itself must be declared abstract. → cannot be instantiated/created → can only be base/parent class or a class that can be inherited by another class. → When an abstract class is inherited , the subclass usually provides implementations for all of the abstract methods in its parent class. → if it does not , then the subclass must also be declared abstract. Why interfaces are implemented/created in OOP paradigm? ➢ There are classes that are not inherited in a singular object, different elements but maybe they have something in common in behavior. → Two or more classes have the same behavior even though not from a same parent class, use realization relationship and create interface. List https://docs.oracle.com/javase/8/docs/api/java/util/List.html

REALIZATION

Test Main Method

SINGLETON

➢ Used when objects are necessarily one, restrict more instances of class Default Constructor: Normal Constructor:

  • Eliminate redundancy through Interface and Abstract Class
  • Drink abstract class