0% found this document useful (0 votes)
45 views

Unit 5 - Basic Object Oriented Design

The document discusses core concepts of object-oriented programming including classes, objects, inheritance, encapsulation, polymorphism, and abstraction. It explains the differences between classes, objects, and interfaces. The document also covers abstract classes, class instantiation, and object-oriented design principles and best practices.

Uploaded by

Bergue Chris
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Unit 5 - Basic Object Oriented Design

The document discusses core concepts of object-oriented programming including classes, objects, inheritance, encapsulation, polymorphism, and abstraction. It explains the differences between classes, objects, and interfaces. The document also covers abstract classes, class instantiation, and object-oriented design principles and best practices.

Uploaded by

Bergue Chris
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

OUbs017212

DESIGN & ALGORITHMS


Unit 5
Basic Object Oriented Design
Objectives
By completing this unit you will be able to:
• Recap on the core concepts of Object-Oriented programming
• Design the different artifacts of an Object-Oriented Program
• Highlight best practices on Object-Oriented design
• Facilitate the transition from requirements to design
Agenda
• Object-Oriented Programming
• Object
• Class
• Abstract Class
• Interface
• Class & Structure
• Object-Oriented Features
Object-Oriented Programming
• OOP is a technique to develop logical modules, such as classes that
contain properties, methods, fields, and events.
• An object is created in the program to represent a class. An object
encapsulates all the features, such as data and behavior that are
associated to a class.
• OOP allows developers to develop modular programs and assemble
them as a software.
• Objects are used to access data and behaviors of different software
modules, such as classes, namespaces, etc.
Object
• They are instance of classes.
• It is a basic unit of a system.
• An object is an entity that has attributes, behavior, and identity.
• Attributes and behavior of an object are defined by the class
definition.
• Objects have states and behaviors.
• Example: A dog has attributes such as color, name, breed as well as
behaviors such as wagging the tail, barking, eating.
• An object is an instance of a class.
Class
• A class describes all the attributes of objects, as well as the methods that implement
the behavior of member objects.
• It is a comprehensive data type, which represents a blue print of an objects. It is a
template of object.
• A class can be defined as the primary building block of OOP. It also serves as a
template that describes the properties, state, and behaviors common to a particular
group of objects.
• A class contains data and behavior of an entity.
• For example, the aircraft class can contain data, such as model number, category, and
color and behavior, such as duration of flight, speed, and number of passengers.
• A class inherits the data members and behaviors of other classes by extending from
them.
Class & Object
Instantiation
• In programming, instantiation is the creation of a real instance or
particular realization of an abstraction or template such as a class of
objects or a computer process. In other words, using Java, you
instantiate a class to create a specific class that is also an executable
file you can run in a computer.
Abstract Class
1. A class can extend only one abstract class
2. The members of abstract class can be private as well as protected
3. Abstract classes should have subclasses
4. Any class can extend an abstract class
5. Methods in abstract class can be abstract as well as concrete
6. There can be a constructor for abstract class
7. The class extending the abstract class may or may not implement any
of its method
8. An abstract class can implement methods
Abstract Class
• Abstract Class allow default method implementations
• Example: Animal sound differs from one animal to another, there is no
point to implement this method in parent class. Class Animal that has
a method sound() and the subclasses of it like Dog, Lion, Horse, Cat
override this method to give its own implementation details, like Lion
class will say ‘Roar’, Dog class will say “Woof”, etc
Interface
1. A class can implement several interfaces
2. An interface can only have public members
3. Interfaces must have implementations by classes
4. Only an interface can extend another interface
5. All methods in an interface should be abstract
6. Interface does not have constructor
7. All methods of interface need to be implemented by a class implementing that
interface
8. Interfaces cannot contain body of any of its method.
9. Interface is very important to achieve multiple inheritance.
Class & Structure
• Access specifiers, such as public, private, and protected, are identically used in
structures and classes to restrict the access of their data and methods outside
their body.
• The access level for class members and struct members, including nested
classes and structs, is private by default. Private nested types are not
accessible from outside the containing type.
• Both can have constructors, methods, properties, fields, constants,
enumerations, events, and event handlers.
• Both structures and classes can implement interfaces to use multiple-
inheritance in code.
• Both structures and classes can have constructors with parameter.
Object-Oriented Principles
• Abstraction, refers to the process of exposing only the relevant and essential
data to the users without showing unnecessary information.
• Polymorphism, allows you to use an entity in multiple forms.
• Encapsulation, prevents the data from unwanted access by binding of code
and data in a single unit called object.
• Inheritance, promotes the reusability of code and eliminates the use of
redundant code. It is the property through which a child class obtains all the
features defined in its parent class. When a class inherits the common
properties of another class, the class inheriting the properties is called a
derived class and the class that allows inheritance of its common properties
is called a base class.
Summary

• Object Oriented programming maps real world objects and classify them into classes
according to similar attributes
• Structures and classes are the most important data structures used in Object-Oriented
programming
• Abstraction refers to the process of exposing only the relevant and essential data to
the users without showing unnecessary information.
• Polymorphism - Allows you to use an entity in multiple forms.
• Encapsulation - Prevents the data from unwanted access by binding of code and data
in a single unit called object.
• Inheritance - Promotes the reusability of code and eliminates the use of redundant
code. It is the property through which a child class obtains all the features defined in
its parent class
Summary

• Access to classes are generally defined as Public, Private or Protected


• The action of instantiation in OO programming is similar to
initialization in procedural programming
• Examples of OO programming languages are C++, Java, Android, etc.
• An abstract class is one which is not instantiated, an abstract method
is a method without implementation
• An abstract class without implementation is almost like an interface
despite many differences between them
Thank You For Your Attention

Any Question?
Activities
1. What is the difference between an OO programming and procedural programming?
2. Explain the concept of object and classification in object oriented programming.
3. How does the principle of inheritance make programming easier? Support your answer
with the help of a diagram.
4. Describe the principles of encapsulation, polymorphism and abstraction in object oriented
language.
5. Which of the following are object oriented languages?
• Android
• Visual Basic 6.0
• Csharp
• C
• C++
• Java
Activities
6. Explain the following keywords related to classes:
• Public
• Private
• Protected
• Abstract
• Extends
• implements
7. Explain how a constructor is used in a class. What is a static constructor?
8. What do you understand by “instantiation”?
9. With the help of an example, illustrate the notion of methods in OO programming.
How can a method be overloaded?
10. Explain “events notifications” in Object-Oriented programs.

You might also like