Lecture 1 - Introduction To OOP
Lecture 1 - Introduction To OOP
Programming (OOP)
Lecture 1
The Institute of Finance Management
Faculty of Computing, Information Systems and
Mathematics
Dr. Mandari, H
Computer Programming
• An algorithm is a step-by-step process.
• A computer program is a step-by-step set of
instructions for a computer.
• Every computer program is an algorithm.
• The history of computer programming is a
steady move away from machine-oriented views
of programming towards concepts and
metaphors that more closely reflect the way in
which we ourselves see & understand the world
Programming Languages
• Programming languages allow programmers
to develop software.
• The three major families of languages are:
1. Machine languages
2. Assembly languages
3. High-Level languages
Machine Languages
• Comprised of 1s and 0s
• The “native” language of a computer
• Difficult to program – one misplaced 1 or 0
will cause the program to fail.
• Example of code:
1110100010101 111010101110 10111010110100
10100011110111
Assembly Languages
• Assembly languages are a step towards easier
programming.
• Assembly languages are comprised of a set of
elemental commands which are tied to a specific
processor.
• Assembly language code needs to be translated to
machine language before the computer processes it.
• Example:
ADD 1001010, 1011010
High-Level Languages
• High-level languages represent a giant leap towards
easier programming.
• The syntax of HL languages is similar to English.
• Example:
grossPay = basePay + overTimePay
• Interpreter – Executes high level language programs
without compilation.
• Historically, we divide HL languages into two groups:
1. Procedural languages
2. Object-Oriented languages (OOP)
Procedural Languages
• Early high-level languages are typically called
procedural languages.
• Procedural languages are characterized by
sequential sets of linear commands.
• The focus of such languages is on structure.
• Examples include C, COBOL, Fortran, LISP, Perl,
HTML, VBScript
Object-Oriented Languages
• The focus of OOP languages is not on
structure, but on modeling data.
• Programmers code using “blueprints” of data
models called classes.
• Examples of OOP languages include C++,
Visual Basic.NET and Java.
Object-Oriented Programming Languages
• Pure OO Languages
– Eiffel, Actor, Emerald, JADE, Obix, Ruby, Python,
Scala, Smalltalk, Self.
• Hybrid OO Languages
– Delphi/Object Pascal, C++, Java, C#, VB.NET,
Pascal, Visual Basic, MATLAB, Fortran, Perl, COBOL
2002, PHP, ABAP, Ada 95.
OOP Basic Terminology
• Object
– usually a person, place or thing (a noun)
• Method
– an action performed by an object (a verb)
• Property or attribute
– Characteristics of certain object.
• Class
– a category of similar objects (such as automobiles),
does not hold any values of the object’ s
attributes/properties
Classes and Objects
• A class is a prototype, idea, and blueprint for
creating objects.
• An object is an instance of a class.
• For example, in Java we define classes, which
in turn are used to create objects
• A class has a constructor for creating objects
• Class is composed of three things: its name,
attributes/properties, and methods.
Classes & Objects
• A class is a
definition of
objects with the
same properties
and the same
methods.
Classes Example
Object Relationship
HAS-A Relationship
• Association or the “HAS-A”
Teacher Student
Relationship
– One object knows about another object Laptop Mouse
– One object has a reference to another Driver Car
object
Host Parasite
• Inheritance or the “IS-A”
Relationship
– Allows an object to extends to another
object
– Gives ideas to the object TEACHER PERSON STUDENT
eatMeat() squawk()
Roar() fly()
Griffin
Abstraction
• Abstraction allows programmers to represent complex real
world in the simplest manner.
• In abstraction we represents the major attributes only
• It is a process of identifying the relevant qualities and
behaviors an object should possess, in other word
represent the necessary features without representing the
back ground details
• You should always use abstraction to ease reusability, and
understanding for the design and enable extension.
• When we design the abstract classes, we define the
framework for later extensions.
Abstraction
• An abstract class, which declared with the
“abstract” keyword, cannot be instantiated.
• It can only be used as a super-class for other
classes that extend the abstract class.
• Abstract class is a design concept and
implementation gets completed when it is
being realized by a subclass.
Abstraction - type of classes
Abstraction
• An abstract class is a class that may not have any
direct instances.
• An abstract operation is an operation that it is
incomplete and requires a child to supply an
implementation of the operation.
Polymorphism
• Polymorphism refers to a programming
language's ability to process objects differently
depending on their data type or class.
• Generally, the ability to appear in many forms.
• More specifically, it is the ability to redefine
methods for derived classes.
Polymorphism
• For example, given a base class shape,
polymorphism enables the programmer to
define different area methods for any number
of derived classes, such as circles, rectangles
and triangles.
• No matter what shape an object is, applying
the area method to it will return the correct
results.
Polymorphism
• Polymorphisms is a generic term that means 'many
shapes'. More precisely Polymorphisms means the
ability to request that the same methods be
performed by a wide range of different types of
things.
• In OOP, polymorphisms is a technical issue and
principle.
• It is achieved by using many different techniques
named method overloading, operator overloading,
and method overriding.
Polymorphism
• In Java, two or more classes could each have a
method called output
• Each output method would do the right thing
for the class that it was in.
• One output might display a number
(output.number) in one class, whereas it
might display a name (output.text) in another
class.
Polymorphism
• It is the ability to look at a class in its parent
image.
• Lets see the robot example throughout the
following few slides
Unified Modelling Language
• UML is a diagramming tool for describing and documenting
object oriented applications
• Programming language independent
• Used for modelling an application before its engineered
• Twelve different diagrams in all, with many complex details
• Generally though only two of these are used regularly
– Class diagrams
– Sequence diagrams
Unified Modelling Language
• Class Diagrams
– Describe classes and interfaces
– …their properties
– …their public interface
– …and their relationships (e.g. inheritance, aggregation,
composition)
• Sequence Diagrams
– Describe how objects send messages to one another
– Useful for describing how a particular part of an application works
• We’ll be covering just class diagrams
– Very useful for describing APIs and discussing OO applications
UML Classes
• Box with 3 sections
• The top contains the class
name
• The middle lists the classes
attributes
• The bottom lists the classes
methods
• Can indicate parameters and
return types to methods, as
well as their visibility
UML Association
• A line between two classes
indicates a relationship
• Extra information can be added to
describe the relationship
• Including
– Its name
– The roles that the classes play
– The cardinality of the relationship
(how many objects are involved)
• E.g. a Person works For a
Company, which has many
employees
UML comments
• Useful for adding
text for the readers
of your diagram
• The symbol looks
like a little note,
with a dotted line
joining it to the
class or relationship
that its describing
UML Aggregation
• Aggregation (a whole-part
relationship) is shown by
a line with clear diamond.
• As aggregation is a form
of relationship you can
also add the usual extra
information
• i.e.
– Name
– Roles
– Cardinality
UML Inheritance
• Inheritance is shown by a
solid arrow from the sub-
class to the super-class
• The sub-class doesn’t list
its super-class attributes
or methods,
• Unless its providing its
own alternate version
(i.e. is extending the
behaviour of the base
class)
Concluding Remarks
• Advantages of OOP
– Code reuse & recycling
– Improved software-development productivity
– Improved software maintainability
– Faster development
– Lower cost of development
– Higher-quality software
– Encapsulation
Disadvantages of OOP
• Steep learning curve
• Could lead to larger program sizes
• Could produce slower programs
OOP Suitability
• Object oriented programming is good in
complex projects or modular type of systems.
It allows simultaneous system development
teams and also could aid in agile system
development environments like Extreme
Programming.
END