You are on page 1of 47

IS 305 OBJECT ORIENTED

PROGRAMMING
MID-SEMESTER EXAM REVISION
LEARNING OUTCOMES

Review concepts in:


Structured programming
Object-oriented programming
Classes and objects
Constructor
Inheritance
Polymorphism
Encapsulation 2
CONTENTS
Structured programming
Object-oriented programming
Classes and objects
Constructor
Inheritance
Polymorphism
Encapsulation
Summary
Exercises 3
STRUCTURED PROGRAMMING

Programming approach where each module has


one start point and one end point.
Uses constructs:
Sequence
Selection
Repetition
4
STRUCTURED ANALYSIS

Technique to determine what processing is required an


organize those requirements by using structured analysis
models.

5
STRUCTURED DESIGN

The design process of organizing a program into a


set of modules and organizing those modules into a
hierarchical structure.

6
TOP-DOWN PROGRAMMING

Concept related to structured programming.


Divides more complex programs into a hierarchy of program
modules.
One module at the top of the hierarchy controls program execution
by
calling lower level modules as required.
7
STRUCTURED APPROACH

Software or system development approach that involves


structured analysis, structured design and structured
programming

8
OBJECT-ORIENTED PROGRAMMING

Extension of structured programming (subset of


procedural programming) (Farrell, 2010).
It focuses on Objects.
Programming using object-oriented language

9
OBJECT-ORIENTED ANALYSIS

The process of identify and defining the use cases and set
of objects(classes) in the new system.

10
OBJECT-ORIENTED DESIGN

Defining all of the types of objects necessary to


communicate with people and devices in the system,
showing how objects interact to complete tasks, and
refining the definition of each type of object so that it can
be implemented with a specific language or environment.

11
OBJECT-ORIENTED APPROACH

Software development approach that is based on the view


that a system is a set of interacting objects that work together.

Combination of object-oriented analysis, object-oriented


design and object-oriented programming

12
UNIFIED MODELING LANGUAGE (UML)

Graphical language for object-oriented analysis and design that


gives a standard way to write software systems models.

It helps to visualize , specify , construct and document the artifacts of


an object-oriented system.

Developed in 1990
13
UML DIAGRAMS

Use Case Diagram


UML diagram that describes how external entities will use the
a system.

Class Diagram
UML diagram that models a class as a rectangle with three
compartments
14
CLASS DIAGRAM COMPARTMENTS

Top compartment
Contains the name of the class centered horizontally in
boldface type.

Middle compartment
Contains the class's attributes, which corresponds to instance
variables and properties in C#.
15
CLASS DIAGRAM COMPARTMENTS, CONT.

Bottom compartment
Contains the class's operations, which corresponds to
methods in C#.

List the operation name followed by a set of parentheses.

16
NOTATION

17
CLASSES AND OBJECTS

18
CLASS

Mechanism that binds properties(attributes or data


members) and methods in a single unit.
Data type of an object.
Memory space is not allocated when it is created.
Definition is created once and it can be reused
19
OBJECT

Instance of a class
Variable of a class
Memory space is allocated when it is created.
Created many time as required

20
PROPERTY

Allow for access to objects values through:


get accessor
Read the values of data members or the properties.

set accessor
Store the values of data members or the properties
21
CONSTRUCTOR

22
CONSTRUCTOR

Special kind of method.


Invoked to construct an object.
Initializes an object.
Rules
Should have the same name as the class
Should not have a return type- not even void
Invoked using the new operator when creating an object
23
TYPES OF CONSTRUCTORS

No argument constructor
Constructor with zero argument

Single argument constructor


Constructor with one argument

24
TYPES OF CONSTRUCTORS, CONT.

Two arguments constructor


Constructor with two arguments

Many argument constructor


Constructor with more than two arguments

25
INHERITANCE

26
INHERITANCE
Core principle or concept in object-oriented programming
Allows programmers to write new classes that inherit properties,
fields and methods of an already existing class.
Allows programmers to write much less code.
Allows for software reusability.
Allows for creation of a first class and then creating another class
which inherits properties, fields and methods of the first class.
27
SUPER CLASS

Parent class
Hold the properties, fields and methods that a sub class
wants
to extend and use appropriately in the sub class.
Base class
28
SUB CLASS

Child class
Extents properties, fields and methods of the super class.
It can have its own properties, fields and methods or modify
the super classes properties, methods and fields.
Derived class

29
RELATIONSHIPS

is-a relationship
Example: A reptile is-a creature

has-a relationship
Example: A reptile has-a face
30
POLYMORPHISM

31
POLYMORPHISM

Poly means many


Morphism means behaviors
Therefore, polymorphism means many behaviors

32
POLYMORPHISM, CONT.

Polymorphism is the ability for classes to provide different


implementations of methods that are called by the same name.

Polymorphism allows a method of a class to be called without


regard to what specific implementation it provides.

33
TYPES OF POLYMORPHISM

34
TYPES OF POLYMORPHISM

35
METHOD OVERLOADING
Creating a multiple methods in a class with same name but different
parameters and types.
Example of compile time polymorphism which is done at
compile time.
Can be achieved by
By changing the number of parameters used.
By changing the order of parameters.
By using different data types for the parameters
36
METHOD OVERRIDING

Having two methods with same name and signatures(parameters).


One method in parent class and the other method is in the derived class.

Can be achieved by
Using inheritance
Using virtual and override keywords in the respective methods.
Virtual keyword in parent class method.
Override keyword in derived class method
37
ENCAPSULATION

38
ENCAPSULATION

An important concept in Object-Oriented Programming.


Encapsulation:
Hides implementation details in one class from another class.
Controls access to data members.
Also known as Data Hiding or Information Hiding.

39
WHY ENCAPSULATION?

Encapsulation is used:
To protect data
To make classes easy to maintain

40
PRIVATE DATA MEMBERS

Encapsulation allows for data members to be only


accessible within the same class.

Also restricts access to data members from outside of the


class.
41
ACCESS MODIFIERS

Allow indirect access to data from other classes.


Public subprograms that either Get or Set the value
of private attributes.

42
PUBLIC ACCESSORS AND MUTATORS

Public accessors and Mutators are set up to update the data


members.
Accessors
Example: getID

Mutators
Example: setID

43
CONTROLLING ACCESS TO MEMBERS
The Public and Private access modifiers control access to a classs
variables, methods and properties.
Public any class is able to view the data.
Private no other class, except the class where the variable is
held, is able to see the contents of the variable.
If a class member is not declared with an access modifier, it has
Private access by default.
44
CONTROLLING ACCESS TO MEMBERS, CONT.

The outside class can be able to access the private data members
through the public method.

This way data can only be accessed by public methods thus making
the private fields and their implementation hidden for outside
classes.
45
SUMMARY

Structured programming
Object-oriented programming
Classes and objects
Constructor
Inheritance
Polymorphism
Encapsulation
46
EXERCISES

Review and answer the conceptual exercises.


Review and understand the programming exercises.

47

You might also like