Object Oriented Programming

Similar documents
Chapter 2: Java OOP I

Object oriented programming Concepts

Basics of Object Oriented Programming FCITR MAGAZINE DR. SHAKEEL AHMAD

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming


Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Principles of Object Oriented Programming. Lecture 4

Java Object Oriented Design. CSC207 Fall 2014

Chapter 5: Classes and Objects in Depth. Information Hiding

Software Development. Modular Design and Algorithm Analysis

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Advanced Object Oriented PHP

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

What are the characteristics of Object Oriented programming language?

ITI Introduction to Computing II

Class and Functions. Reusable codes

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005

Object-Oriented Technology. Rick Mercer

Example: Fibonacci Numbers

Object- Oriented Design with UML and Java Part I: Fundamentals

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Introduction to Java and OOP. Hendrik Speleers

Advanced Database Applications. Object Oriented Database Management Chapter 13 10/29/2016. Object DBMSs

ITI Introduction to Computing II

Defining Classes and Methods

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Introduction. Object Orientated Analysis and Design. Benjamin Kenwright

Object-Oriented Programming

Introduction to Object-Oriented Programming

Inheritance and Polymorphism

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Object-Oriented Programming Concepts

Classes, Objects, and OOP in Java. June 16, 2017

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Classes, objects, methods and properties

CHAPTER 5 GENERAL OOP CONCEPTS

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Chapter3: Introduction to Classes and Objects

Data Structures (list, dictionary, tuples, sets, strings)

What is Inheritance?

Designing and Implementing Classes Topic 6

JAVA: A Primer. By: Amrita Rajagopal

JAVA OBJECT-ORIENTED PROGRAMMING

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )

CS200: Advanced OO in Java

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.

Principles of Programming Languages, 2

CS153: Compilers Lecture 11: Compiling Objects

Subtyping (Dynamic Polymorphism)

Elementary Concepts of Object Class

Lecture Notes on Programming Languages

IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.

Overview. OOP: model, map, reuse, extend. Examples of objects. Introduction to Object Oriented Design

Inheritance and Interfaces

Chapter 5 Object-Oriented Programming

Lecture 6 Introduction to Objects and Classes

Computer Science 4U Unit 1. Programming Concepts and Skills Modular Design

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Object Oriented Concepts. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Lecture 2: Java & Javadoc

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

CS 2110 AEW SIGN UP FOR 1 CREDIT S/U COURSE!!!

CSCI 253. Outline. Background. George Blankenship 1

Object-Oriented Programming

CS 2110 AEW. Machine Language. Outline. Assembly Language. High-Level Language 1/26/2012

About 1. Chapter 1: Getting started with oop 2. Remarks 2. Examples 2. Introduction 2. OOP Introduction 2. Intoduction 2. OOP Terminology 3.

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226

OBJECT ORIENTED PROGRAMMING

CSC 1214: Object-Oriented Programming

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Week 3 Classes and Objects

CS-202 Introduction to Object Oriented Programming

Introduction to OO Concepts

C++ Inheritance and Encapsulation

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CSCI 2041: Object Systems

Goals of the Lecture OO Programming Principles

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

Data Abstraction. Hwansoo Han

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Object Orientated Analysis and Design. Benjamin Kenwright

MIS Systems & Infrastructure Lifecycle Management 1. Week 11 March 31, 2016

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object Oriented Programming with Java

BASIC CONCEPT OF OOP

Chapter 5. Inheritance

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

CS 32. Lecture 1: oops

Designing data types. Overview. Object Oriented Programming. Alan Kay. Object Oriented Programming (OOP) Data encapsulation. Checking for equality

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Inheritance, and Polymorphism.

Object Oriented Programming. Michał Bereta

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Transcription:

Object Oriented Programming Ray John Pamillo 1/27/2016 1 Nokia Solutions and Networks 2014

Outline: Brief History of OOP Why use OOP? OOP vs Procedural Programming What is OOP? Objects and Classes 4 Pillars of OOP Interfaces Demo / Exercises 2 Nokia Solutions and Networks 2014

Brief History of OOP (Object Oriented Programming) - 1950 s to 60 s : object as items (LISP atoms) with properties - 1961 : Simula 67, introduced the concepts of OOP - 1966 : Alan Kay, while working with Ivan Sutherland (doing graphics programs), developed his views on objects and programming - 1968 : Kay met Seymour Papert and learned of Logo, a Lisp dialect - 1970 s : Smalltalk, by Alan Kay at Xerox Parc, is considered the pure OO language (everything are objects). This work influenced the Lisp community to adopt OOP features. OOP gained momentum at this time. - 1980 s : C++, by Bjorn Stroustrup, is an integration of OOP into C language. - 1990 s : Java, by James Gosling at Sun Microsystems, a simpler version of C++ 3 Nokia Solutions and Networks 2014

4 Nokia Solutions and Networks 2014 Why Use OOP?

Why Use OOP? - It is widely used. - It improves maintainability of large software projects. - It encourages software reuse. - It makes programming easier. - It can lead to more expressive code. function dothemostexpressivethingpossible(){ // do something expressive here 5 Nokia Solutions and Networks 2014

6 Nokia Solutions and Networks 2014 OOP vs PP

Object Oriented Programming Procedural Programming - Gives importance on objects and data. - Data is bundled. - Realistic Modeling. - Scalable and reusable - Easier to maintain. - Resilient to change. - Can make simple problems complex - Program flow can be difficult to track - Tends to consume more memory - Gives importance on operations. - Data is exposed. - Difficult to relate with real world objects. - Difficult to create new data types. - Debugging/refactoring becomes harder as the codebase grow - Relatively simple. - Program flow is straightforward. - Needs less memory. 7 Nokia Solutions and Networks 2014

8 Nokia Solutions and Networks 2014 What is OOP?

Object Oriented Programming - It is a design philosophy. - It is about objects objects in the program correspond to real world objects, hence the term modeling 9 Nokia Solutions and Networks 2014

Real-world Objects - They all have STATE and BEHAVIOR. Software Objects - Consists of state and behavior. - Stores its state in FIELDS (or variables) and exposes its behavior through METHODS (or functions). 10 Nokia Solutions and Networks 2014

Benefits of bundling code into objects Modularity Information-hiding Code re-use Pluggability and debugging ease 11 Nokia Solutions and Networks 2014

Class - A representation of a type of object. - A blueprint, plan or template that describes the details of an object. - A factory, that is able to mass produce objects. Object - An instance of a class. 12 Nokia Solutions and Networks 2014

Class class Person { Object Person objectperson = new Person(); 13 Nokia Solutions and Networks 2014

The Class as a Blueprint is composed of A declaration of a set of variables that the object will possess. A declaration of the set of operations that the object will provide. A set of function definitions that implements each of these operations. 14 Nokia Solutions and Networks 2014

Components of a Class Instance Variables the set of variables that the object will possess. hold the state of a particular object Methods the set of operations that the object will provide. functions 15 Nokia Solutions and Networks 2014

A Class example in Java public class Person{ private String name; private int age; public Person(){ public String getname(){ return name; public int getage(){ return age; 16 Nokia Solutions and Networks 2014

Things to remember: DRY Don t Repeat Yourself KISS Keep It Simple, Stupid 17 Nokia Solutions and Networks 2014

18 Nokia Solutions and Networks 2014 The 4 Pillars of OOP

The 4 Pillars of OOP Abstraction Encapsulation Inheritance Polymorphism 19 Nokia Solutions and Networks 2014

Abstraction Representation of the essential characteristics of an object/class that differentiates it from other objects/classes with respect to the viewer s perspective. The concept of moving the focus from the details and concrete implementation of things, to the types of things (i.e. classes), the operations available (i.e. methods), etc, thus making the programming simpler, more general, and more abstract. 20 Nokia Solutions and Networks 2014

Abstraction The abstract keyword. Use of methods without body / implementation. 21 Nokia Solutions and Networks 2014

Encapsulation Hiding of unnecessary behaviors/attributes from the user and show only those that the users can directly use. Hiding of Implementation 22 Nokia Solutions and Networks 2014

Encapsulation Use of the access keywords: public, private, protected Use of getters and setters - Keep the variables private, and expose only the relevant methods when modifying these variables 23 Nokia Solutions and Networks 2014

Inheritance A mechanism which helps you to generalize common attributes and behaviors in separate classes from various subclasses. The relationship between the Parent Class and the Children Classes has an Is A relationship 24 Nokia Solutions and Networks 2014

Inheritance Use of the extends keyword Method overriding 25 Nokia Solutions and Networks 2014

Polymorphism Ability of an object to behave differently under different circumstances. An alternative to if else if else and switch case statements. 26 Nokia Solutions and Networks 2014

Interfaces a group of related methods with empty bodies The interface as an abstraction. The interface as an encapsulation. The interface as a means for polymorphism. Programming to an interface. - Interfaces are just CONTRACTS or signatures and they don t know anything about implementations 27 Nokia Solutions and Networks 2014

Interfaces : Examples public interface Vehicle { void start(); void turn(string direction); public interface Flight { int getaltitude(); 28 Nokia Solutions and Networks 2014

Programming to an Interface public class Car implements Vehicle { void start(){ // car implementation of start void turn(string direction){ // car implementation of turn public class Airplane implements Movement, Flight { void start(){ // airplane implementation of start void turn(string direction){ // airplane implementation of turn //Flight specific methods int getaltitude(){ int altitude=o; // altitude implementation return altitude; 29 Nokia Solutions and Networks 2014

Programming to an Interface public class TestVehicles { public static void main(string [] args){ Vehicle vehicle1 = new Car(); Vehicle vehicle2= new Plane(); Vehicle[] vehicles = {vehicle1, vehicle2; for(i=0; i<vehicles.length; i++){ vehicles[i].start(); vehicles[i].turn( right ); vehicles[i].turn( left ); 30 Nokia Solutions and Networks 2014

31 Nokia Solutions and Networks 2014 DEMO

References: McLaughlin, B., Pollice G., & West D. (2007). Head First : Object-Oriented Analysis and Design. USA: O Reilly Media Inc. The Java Tutorials. Retrieved Jan 25, 2016 from https://docs.oracle.com/javase/tutorial/java/concepts/ Difference Between Object-oriented Programming and Procedural Programming Languages. Retrieved Jan 22, 2016 from https://neonbrand.com/website-design/procedural-programming-vsobject-oriented-programming-a-review/ A Brief History of Object-Oriented Programming. Retrieved Jan 25, 2016 from http://web.eecs.utk.edu/~huangj/cs302s04/notes/oo-intro.html Was object-oriented programming a failure?. In Quora. Retrieved Jan 25, 2016 from https://www.quora.com/was-object-oriented-programming-a-failure Back to Basics Three or Four OOP Pillars?. Retrieved Jan 25, 2016 from http://themoderndeveloper.com/the-modern-developer/back-to-basics-three-or-four-oop-pillars/ 32 Nokia Solutions and Networks 2014