Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Lecture 1

Introduction to Object Oriented


Programming
Introduction
Instructor
Abdul Haseeb Shujja
Office hours
Mon-Fri 4:00 – 6:00 PM
Email
abdul.shujja@umt.edu.pk
Moodle Enrollment Key
OOP2019
Marks Distribution
Assignments 15
Class Participation + 5+5
Attendance
Quizzes 10
Semester Project 10
Lab Exam 15
Midterm 15
Final exam 25
2 types of assignments
Take home
Lab
Quizzes will mostly be unannounced (no retakes)
3-4 person groups for project
Rules & tips
No cheating allowed….EVER!
Do everything yourself
Try “googling” the errors/problems you get
If you cant find solutions anyway, come to me
or email me your code with your problem along
with a description of what you have tried so far.
Late submissions will result in marks
deduction (No Exceptions)
10% every day
Want a good grade?
PRACTICE
Course Outline
Session 1: Introduction to OOP, Objects and
Classes
Session 2: C# basics - I
Session 3: C# basics - II
Session 3: Encapsulation and Abstraction
Session 5: Constructors and Destructors
Session 6: Inheritance
Session 7: Polymorphism
Session 8: Association, Aggregation and
Composition
Session 9: MIDTERM
Course Outline
Session 10: Interfaces, Generics and
Delegates
Session 11: GUI, Windows Forms and WPF
Session 12: Event and Exception Handling
Session 13: Revision
Session 14: Lab Exam
Session 15: Project Presentations and
revision
FINAL EXAM
Basic terminology
Object
 Usually a person, place or thing (a noun)
Method
 An action performed by an object (a verb)
Attribute
Description of objects in a class
Class
A category of similar objects (such as
automobiles)
Does not hold any values of the object’s
attributes
Object Oriented
Programming
Objects have both data and methods
 Objects of the same class have the same
data elements and methods
 Objects send and receive messages to
invoke actions

Key idea in object-oriented


programming:
 
The real world can be accurately described
as a collection of objects that interact.
Example for attributes and
methods

Attributes Methods

Manufacturer’s Define data


name items (specify
Model name manufacturer’s
Year made name, model,
Color year, etc.)
Number of Change a data
doors item (color,
Size of engine engine, etc.)
Display data
etc.
items
Calculate cost
Why OOP?

 Save development time (and cost) by


reusing code
once an object class is created it can be used
in other applications
 Easier debugging
classes can be tested independently
reused objects have already been tested
Object Oriented Design
Principles
Encapsulation
Abstraction
Inheritance
Polymorphism
Encapsulation

The action of enclosing something in or as


if in a capsule.
Also known as data hiding
Only object’s methods can modify
information in the object.

Analogy:
 ATM machine can only update accounts of
one person when an authorized transaction is
made
Abstraction
Focus only on the important facts about the
problem at hand
To design, produce, and describe so that it
can be easily used without knowing the
details of how it works.

Analogy:
 When you drive a car, you don’t have to
know how the gasoline and air are mixed and
ignited.
 Instead you only have to know how to use
the controls.
Polymorphism
The same word or phrase can mean
different things in different contexts

Analogy:
In English, bank can mean side of a river or a
place to put money
Inheritance
Inheritance—a way of organizing classes
 Term comes from inheritance of traits like
eye color, hair color, and so on.
 Classes with properties in common can be
grouped so that their common properties
are only defined once.
 Superclass – inherit its attributes &
methods to the subclass(es).
 Subclass – can inherit all its superclass
attributes & methods besides having its
own unique attributes & methods.
Analogy?
Object Oriented
Languages
Five Rules
Everything is an object.
A program is a set of objects telling each
other what to do by sending messages.
Each object has its own memory (made up of
other objects).
Every object has a type.
All objects of a specific type can receive the
same messages.
All object oriented languages generally
follow these rules.
Object Oriented
Languages
Pure Object Oriented Languages:
Java
C#
JavaScript
Eiffel
Hybrid Languages
C++
Objective-C
Object-Pascal (Delphi)
Object Oriented Design
How to identify a class?
First identify its objects.
We’ll use the example of a car
Then identify what properties these object
have in common
Engine, color, seats, body, wheels etc.
These will be our attributes
Now identify the common actions that the
objects can perform
Accelerate, brake, ignition, switching off, turn
etc.
These will be the functions/methods of the
class.
Now, write the class.
Classes: A simple example
(Car)
class car
{
public string color{set;get;}
public void MyColor()
{
Console.WriteLine("My color is “+color);
}
} //end class

*do not copy and run this code, use the text file
provided on LMS instead
Usage
Now, to use this class in Main()

class Program
{
static void Main(string[] args)
{
car c1=new car();
c1.color="red";
c1.MyColor();
Console.ReadKey();
}
}

You might also like