Introduction to Object-Oriented Concepts

Slides:



Advertisements
Similar presentations
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Advertisements

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
Object-Oriented Software Testing. C-S 5462 Object-Oriented Software Testing Research confirms that testing methods proposed for procedural approach are.
Writing Classes (Chapter 4)
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences University of Scranton October 18, 2015October 18, 2015October 18, 2015.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Salman Marvasti Sharif University of Technology Winter 2015.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 5.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
INFSY 535.  Small systems  Larger systems 1.Understand the program requirement- what 3. Write and test each part (unit testing) 4. Maintenance 2. Specify.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOP Basics Classes & Methods (c) IDMS/SQL News
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
Object-Oriented Design
Visit for more Learning Resources
Object Oriented Programming
Objects as a programming concept
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Sachin Malhotra Saurabh Choudhary
Concepts of Object Oriented Programming
MPCS – Advanced java Programming
Inheritance and Polymorphism
Objects as a programming concept
The Object-Oriented Thought Process Chapter 1
About the Presentations
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences
Implementing Abstract Classes
Computer Programming.
Inheritance Basics Programming with Inheritance
Chapter 10 Thinking in Objects
Object-oriented Design in Processing
The Object-Oriented Thought Process Chapter 07
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Programming paradigms
Computer Programming with JAVA
Software Design Lecture : 12.
Introduction to Data Structure
The Object-Oriented Thought Process, Chapter 1
Programming Languages and Paradigms
Object-oriented Design in Processing
Review of Previous Lesson
Introduction to Object-Oriented Concepts in Java
CPS120: Introduction to Computer Science
Lecture 10 Concepts of Programming Languages
Object-oriented Design in Processing
The OOTP is intended to get you thinking about how OO concepts are used in designing object-oriented systems. Note: not talking about OO technologies that.
Introduction to Methods and Interfaces
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Introduction to Object-Oriented Concepts …

What is this class about? Three Questions What is this class about? Why does it matter? How does 331 fit in cs curriculum?

Computational Problems What is computer science? Computer Solution? ? Computational Problems What is this class about?

Solving Problems With The Aid of Computers Communication? Programming language Machine language What is this class about?

Solving Problems With The Aid of Computers Programs Programming language Machine language What is this class about?

Solving Problems With The Aid of Computers Programs Programming language Machine language Address Machine Instruction  0000 0001 1  0000 0010 2  0000 1000 3  0000 0100 4  0000 0000 What is this class about?

Assembly Instructions Solving Problems With The Aid of Computers Programs Programming language Machine language Assembly Instructions push cs pop ds mov ah, 9 int 21h sloop: What is this class about?

Solving Problems With The Aid of Computers Programs Programming language Machine language High-level Program for(int i=0; i<10; i++) System.out.println(list[i]); What is this class about?

Procedural Programming 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include<stdio.h> // function prototype, also called function declaration float square ( float x );                               // main function, program starts from here int main( )               {     float m, n ;     printf ( "\nEnter some number for finding square \n");     scanf ( "%f", &m ) ;     // function call     n = square ( m ) ;                           printf ( "\nSquare of the given number %f is %f",m,n ); }   float square ( float x )   // function definition     float p ;     p = x * x ;     return ( p ) ; What is this class about?

Structure of a Procedural Program Procedural Programming Structure of a Procedural Program function-1() main() In procedural programming a program consists of a set of functions. The first function to be executed is often called ‘main’. What is this class about?

Challenges of Procedural Programming Handling large complex programs. create reuse evolve Large software systems: 4 x 106 – 100 x 106 What is this class about?

Dimensions of Software Complexity Challenges of Procedural Programming Dimensions of Software Complexity Algorithmic Functional Structural structure of the data structure of the program Communicational Computational etc. What is this class about?

Complex programs require systematic development Challenges of Procedural Programming Complex programs require systematic development Requirements Analysis Software Design Implementation Testing Deployment Evolution What are the most difficult phases of the software process?

Complex programs require systematic design Challenges of Procedural Programming Complex programs require systematic design Requirements Analysis Software Design Implementation Testing Deployment Evolution Software design is arguably the most difficult phase of the software lifecycle.

Programming Paradigm Evolution Object-Oriented Programming, C++, Java Procedural Programming: C, Pascal, Fortran Assembly Language Programming Machine Language Programming OOP provides better tools for developing and managing complex programs. What is this class about?

Object-Oriented Programming using Java What is this class about? Object-Oriented Programming using Java OOP provides better tools for developing and managing complex programs. What is this class about?

Why does it matter? Object-Oriented Programming (OOP) is a dominant programming paradigm Leverage benefits of Object-Oriented Programming OOP provides better tools for developing and managing complex programs. What is this class about?

What is this class about? Three Questions What is this class about? Why does it matter? How does 331 fit into cs curriculum?

How does 331 fit into cs curriculum? 131 – basic procedural programming 231 – basic structures for managing data 331 – you learn basic OOP 342 - Operating systems (use OOP) 380 – algorithm design (use OOP) 450 – teams develop complex software (use OOP) 455 – includes OO databases

Outline Course overview Getting to know you/me Introduction to Object Oriented Programming (OOP) Concepts Encapsulation Classes & Objects Composition Inheritance Polymorphism

Getting to Know You Name Background Where from Programming background The Man without a Face, oil on panel, 11x14, 2005 – Dae-Woong Nam Name Background Where from Programming background Languages

Fundamental Concepts of OOP Encapsulation Inheritance Polymorphism

Understanding Object Oriented Programming In machine language programming – programs are sequences of bits. In assembly language programming – programs are pieces of code. In procedural programming – programs are collections of interacting functions. In OOP – programs are collections of interacting objects.

Program Structure: OOP vs Procedural Object-Oriented Program global data function-1() main() Procedural Program … function-1() main() global data Class 1 … function-1() global data Class 2 … function-1() global data Class 3

Requirements Analysis OOP & Design OOP simplifies software design because OOP uses larger abstraction units than procedural programming. Requirements Analysis Software Design Implementation Testing Deployment Evolution

Motivating Example Bank Client StockBroker In OOP objects in the real world are modeled as objects in software world. Bank StockBroker Client Programming languages represent real world objects as software classes and objects. OOP narrows the semantic gap between real world and software world.

Example of a Java Class public class Account { private int accNumber; private double balance; public boolean deposit(double amount){ if(amount > 0){ this.balance += amount; return true; } return false; public boolean withdraw(double amount){ if(this.balance >= amount){ this.balance -= amount; }//end of class

Method Signatures The following is all the user needs to know to effectively use a method: The name of the method The parameters passed to the method The return type of the method What he method does

Example of a Java Class public class Account { private int accNumber; private double balance; public boolean deposit(double amount){ if(amount > 0){ this.balance += amount; return true; } return false; public boolean withdraw(double amount){ if(this.balance >= amount){ this.balance -= amount; }//end of class

Abstraction & Software Design In procedural programming: Functions are black boxes. all a user needs to know to effectively use a method is the method signature:

Abstraction & Software Design In procedural programming: Functions are black boxes. all a user needs to know to effectively use a method is the method signature: In OOP: Classes and functions are black boxes. all a user needs to know to effectively use a class is the class interface: The class interface includes a list of method signatures The service the class provides

O-O Programming A fundamental advantage of O-O programming is that the data and the operations that manipulate the data are both contained in the object. For example, when an object is transported across a network, the entire object, including the data and behavior, goes with it.

Class Fundamentals & Modeling in UML Account deposit(amount:double):boolean withdraw(amount:double):boolean accNumber:int balance:double In OOP, class = methods + data We call the data ‘attributes’ of the class

IN-Class Exercise Draw a UML diagram for a class that represents books in a library software system. Name Attributes – define data the class will use. Operations/methods/functions – define the class behavior.

Object Data The data stored within an object represents the state of the object. In O-O programming terminology, this data is called attributes. Eg. 1: UML account class with account number, balance. E.g. 2: Java account class with account number, balance.

Object Data in Java In Java data/variables must be declared before use. Java uses explicit typing. eg. Java account class with attributes: account number and balance. public class Account { private int accNumber; private double balance; … } }//end of class

Fundamental Concepts of OOP Continue … Fundamental Concepts of OOP Encapsulation Inheritance Polymorphism

Encapsulation One of the primary advantages of using objects is that the object need not reveal all its attributes and behaviors. In good O-O design (at least what is generally accepted as good), an object should only reveal the interfaces needed to interact with it.

Encapsulation Details not pertinent to the use of the object should be hidden from other objects. This is called encapsulation. Encapsulation is realized using classes and objects class = variables + methods

Encapsulation & Interfaces The complete list of all the methods a user may call to get a desired behavior from an object is called the provided or public interface of the class/object. This interface also includes any publicly accessible attributes. Interfaces do not normally include attributes only methods. The interface should completely describe how users of the class interact with the class. methods that are part of the interface are designated as public.

Encapsulation & Interfaces public class Account { private int accNumber; private double balance; Public String alias; public void deposit(double amount){ this.balance += amount; } public void withdraw(double amount){ this.balance -= amount; private int changeAccNumber(int accNum){ this.accNumber = accNum; private void getAccountInfo(){ //actual code here }//end of class What is the provided interface for this class?

Encapsulation & Interfaces Normally, if a user needs access to an attribute, then a public method is created to return the attribute. To support OO design, OOP languages facilitates the creation of: Classes = attributes + methods Interfaces = list of method signatures

Encapsulation & Interfaces Example of an interface public interface IAccount { public boolean deposit(double amount); public boolean withdraw(double amount); public int getAccNumber(); public double getBalance(); public void setBalance(double balance); }

Encapsulation: What Exactly Is a Class? A class is a blueprint for an object. The process of creating an object from a class is called instantiation. When you instantiate an object, you use a class as the basis for how the object is built. NB: primitive types vs classes.

Encapsulation: Declaring variables in Java Type of data is explicitly used: int x; float y, z; Integers and floats are built-in types Declare two instances of the Account class: Account obj1, obj2; Classes are user-defined types.

Fundamental Concepts of OOP Encapsulation Inheritance Polymorphism

Inheritance Inheritance allows a class to inherit the attributes and methods of another class. This allows you to create brand new classes by abstracting out common attributes and behaviors.

Mammal Hierarchy Inheritance is sometimes described as the “Is A” relationship. For example, a dog is a mammal.

Mammal Hierarchy

Superclasses and Subclasses The superclass, or parent class, contains all the attributes and behaviors that are common to classes that inherit from it.

Superclasses and Subclasses A shape hierarchy The inheritance arrow shown here is called “Generalization/Sp ecialization” in UML

Inheritance Example in Java Most common form is to use the extends keyword public class Dog extends Mammal{ //class body }

Fundamental Concepts of OOP Encapsulation Inheritance Polymorphism

Polymorphism Polymorphism means many forms. Java provides two forms of polymorphism: Method overloading Operator overloading.

Polymorphism Method overloading Multiple methods with the same name but having different method signatures. public void add(int a, int b); public void add(int a, int b, int c); public void add(String a, String b);

Polymorphism Operator overloading. One operator may be used for different operations 5 + 10 versus “I love ” + “you Mom.”

Composition It is natural to think of objects as containing other objects. A television set contains a tuner and video display.

Composition A computer contains video cards, keyboards, and drives. Although the computer can be considered an object unto itself, the drive is also considered a valid object.

Composition In fact, you could open up the computer and remove the drive and hold it in your hand. Both the computer and the drive are considered objects. It is just that the computer contains other objects such as drives. In this way, objects are often built, or composed, from other objects: This is composition.

Has-a Relationships While an inheritance relationship is considered an Is-a relationship for reasons already discussed, a composition relationship is termed a Has-a relationship.

Has-a Relationships Using the example in the previous section, a television Has-a a tuner and Has-a video display. A television is obviously not a tuner, so there is no inheritance relationship.

Has-a Relationships In the same vein, a computer Has-a video card, Has-a keyboard, and Has-a disk drive. The topics of inheritance, composition and how they relate to each other is covered in great detail later in the course.

How Java Works See https://javarevisited.blogspot.com/2014/06/is-java-interpreted-or-compiled-programming-language.html https://www.quora.com/Is-Java-a-compiled-language-or-interpreted-What-is-the-difference-What-is-the-JIT-compiler

Qu es ti ons? The End ______________________ Devon M. Simmonds Computer Science Department University of North Carolina Wilmington _____________________________________________________________