0% found this document useful (0 votes)
16 views10 pages

SE601 Week 2

The document discusses key concepts in object-oriented programming, including information sharing between objects, generalization, inheritance, extension, overriding, realization, and polymorphism. It explains how these concepts facilitate communication between objects, code reuse, and the creation of flexible and modular systems. Use cases are provided to illustrate the application of these principles in programming.

Uploaded by

maria ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views10 pages

SE601 Week 2

The document discusses key concepts in object-oriented programming, including information sharing between objects, generalization, inheritance, extension, overriding, realization, and polymorphism. It explains how these concepts facilitate communication between objects, code reuse, and the creation of flexible and modular systems. Use cases are provided to illustrate the application of these principles in programming.

Uploaded by

maria ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Software construction and

development Practical

Week 2
Information sharing between objects

In object-oriented programming, objects can share information with each other through
various means, such as method calls, parameter passing, and message passing.
● Method calls allow one object to call a method of another object, passing any
necessary parameters as arguments. This allows the receiving object to use the
information provided by the calling object to perform some action.
● Parameter passing allows one object to pass data directly to another object,
such as passing an object reference to a method. This allows the receiving object
to use the data provided by the calling object to perform some action.
● Message passing is another way for objects to communicate with each other. In
this case, one object sends a message to another object, which can then process
the message and take some action based on its contents.
Data Sharing- UseCase
Generalization

Generalization in object-oriented programming is a mechanism that allows classes to inherit


properties and behavior from other classes. Here are some key points to understand about
generalization:
● Generalization allows for the creation of new classes that are based on existing classes,
but with additional features or behavior.
● The existing class is called the superclass, while the new class is called the subclass.
● Subclasses inherit properties and methods from their superclass, but they can also add
new properties and methods or override existing ones.
● Generalization allows for the creation of hierarchies of classes, with increasingly
specific subclasses inheriting from more general superclasses.
● Generalization can improve the efficiency of code development and maintenance, as it
reduces the need to duplicate code across multiple classes.
Inheritance, Extension, Overriding

● Inheritance: Inheritance is a mechanism that allows a new class to be based on


an existing class. The new class, called the subclass, inherits all the properties
and methods of the existing class, called the superclass. Inheritance allows for
the creation of hierarchical structures of classes, where each subclass is more
specific than its superclass.
● Extension: Extension is the process of adding new properties and methods to a
subclass that are not present in its superclass. This allows the subclass to have
additional features or behavior that are not shared by its superclass.
● Overriding: Overriding is the process of redefining a property or method in a
subclass that is already present in its superclass. This allows the subclass to
modify the behavior of the inherited property or method to suit its own specific
needs.
Inheritance usecase

class Animal {
// eat() function
// sleep() function
};

class Dog : public Animal {


// bark() function

};
Realization

Realization is a concept in object-oriented programming that allows a class to implement the


functionality defined by an interface. Here are some key points to understand about realization:
● An interface is a collection of abstract methods that define the behavior of a class.
● A class can realize an interface by implementing all of the methods defined in the
interface.
● Realization allows for the creation of modular and flexible code, as it allows classes to
share behavior without having to share implementation details.
● Realization is an important part of the design of large, complex systems, as it allows for
easy integration and extension of existing code.
● Realization is often used in combination with other object-oriented programming concepts,
such as inheritance and composition, to create complex, flexible systems that can be
easily modified and extended.
Realization usecase

// Drivable.java

public interface Drivable {

public void drive();

public class Car implements Drivable {

// Must implements all functions of Drivable

public void drive() {

// Do the driving here

}}
Polymorphism

Polymorphism in object-oriented programming allows objects to take on multiple


forms and be treated as different types depending on the context.
● This can take many forms, including method overloading, method overriding, and
interfaces.
● Method overloading allows a class to define multiple methods with the same
name but different parameters, while method overriding allows a subclass to
redefine the implementation of an inherited method.
● Interfaces allow for the creation of multiple classes that share a common set of
methods but with different implementations. These concepts allow for the
creation of flexible and modular code that can be easily modified and extended.
Polymorphism-UseCase
class Vehicle {
class Main {
public void move() {
public static void main(String[] args) {
System.out.println("The vehicle moves"); }}
Vehicle vehicle1 = new Vehicle();

Vehicle vehicle2 = new Car();


class Car extends Vehicle {
Vehicle vehicle3 = new Plane();
public void move() {
vehicle1.move();
System.out.println("The car drives on the road"); }}
vehicle2.move();
class Plane extends Vehicle {
vehicle3.move();
public void move() {
}
System.out.println("The plane flies through the air"); }}
}

You might also like