A Gentle Introduction to (Object-Oriented) Programming

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

Chapter 25 Lists, Stacks, Queues, and Priority Queues
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
1 Classes and Objects in Java Basics of Classes in Java.
Introduction to Object Oriented Design
CSE 105 Structured Programming Language (C)
0 - 0.
11 Contracts CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 6)
Chapter 24 Lists, Stacks, and Queues
John Hurley Cal State LA
Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 11: Priority Queues and Heaps Java Software Structures: Designing.
Addition 1’s to 20.
Chapter 9: Data Structures I
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do.
Chapter 13 – Introduction to Classes
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Introduction to Programming G51PRG University of Nottingham Revision 1
Abstraction, Modularity, Interfaces and Pointers Original slides by Noah Mendelsohn, including content from Mark Sheldon, Noah Daniels, Norman Ramsey COMP.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Introduction to Computer Science I.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 1 – Introduction to Computers, the Internet, and the Web Outline 1.1 Introduction 1.2 What Is a.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
Programming Languages and Paradigms Object-Oriented Programming.
CSCI-383 Object-Oriented Programming & Design Lecture 4.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Course: Object Oriented Programming - Abstract Data Types Unit1: IntroductionSlide Number 1 Introduction Course: Object Oriented Programming Abstract Data.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Chapter 1 Object Orientation: Objects and Classes.
CSE 1301 Lecture 5 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Abstraction CMPS Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction.
C o n f i d e n t i a l 1 Course: BCA Semester: III Subject Code : BC 0042 Subject Name: Operating Systems Unit number : 1 Unit Title: Overview of Operating.
Abstraction ADTs, Information Hiding and Encapsulation.
Salman Marvasti Sharif University of Technology Winter 2015.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
OOP Basics Classes & Methods (c) IDMS/SQL News
Chapter 1 An Overview of Computers and Programming Languages.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
Welcome to OBJECT ORIENTED PROGRAMMING Prepared By Prepared By : VINAY ALEXANDER PGT(CS) KV jhagrakhand.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
RealTimeSystems Lab Jong-Koo, Lim
Introduction to Object-oriented Programming
What Do Computers Do? A computer system is
Inheritance ITI1121 Nour El Kadri.
Chapter 1 – Introduction to Computers, the Internet, and the Web
Abstract Data Types and Encapsulation Concepts
Lecture 1: Introduction to JAVA
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Introduction to Object-oriented Program Design
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Abstract Data Types and Encapsulation Concepts
Procedural Programming
Object oriented vs procedural programming
Programming paradigms
Introduction to Computer Science for Majors II
Introduction to Data Structure
Programming Languages and Paradigms
2.1 Introduction to Object-Oriented Programming
Computer Programming-1 CSC 111
Function of Operating Systems
Presentation transcript:

A Gentle Introduction to (Object-Oriented) Programming Ugur Dogrusoz Associate Professor, Computer Eng Dept, Bilkent University, Ankara, Turkey December 2011 Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ Computer hardware Memory Output Devices Input Devices Hard disk ALU Control Unit Registers Cache CPU Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ Computer software Source file ADDF3 R1,R2, R3 noStudents++; Executable file 11000101011000 1000111010011 Compiler / Linker Operating System Hardware Application Programs User Specific computer Specific JVM Java Bytecode Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ How does a program work A program tells a computer what to do, step by step, to get it to do something useful Computers’ power comes from (nothing more than) Accuracy Speed Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Programming languages Machine Code 101110101… Lowest level: most efficient but (almost) humanly impossible to directly deal with Assembly Language ADDF3 R1,R2, R3 Compiler / Interpreter Language noStudents++ Highest level: easier for humans to express their instructions in Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Object-oriented (OO) prog. languages As opposed to procedural / functional / imperative approach High level general purpose prog. languages Each object (modeled after its real-life equivalent) has certain properties and responsibilities Abstraction, encapsulation, polymorphism, reuse, maintenance OO software = interacting collection of objects Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ OOP basics: memory When a program is loaded into memory for execution: Heap segment Stack segment Text (code) segment Memory Heap Stack Static data Code myObj = new Object(); int i = 9; Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ OOP basics: memory class Node { Object data; Node next; } … main(…) { List myList = new List(); Integer i = new Integer(5); myList.insertFront(i); myList.insertRear(new Integer(8); } class List { private Node first; public Object getFirst() {return(first.data);} public void insertFront(Object newElement) { ... } public void insertRear(Object newElement) { ... } public void delete(Object existingElement) { ... } } Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ OOP basics: memory class Node { Object data; Node next; } … main(…) { List myList = new List(); } myList first: null List 1 3 2 class List { private Node first; public Object getFirst() {return(first.data);} public void insertFront(Object newElement) { ... } public void insertRear(Object newElement) { ... } public void delete(Object existingElement) { ... } } null 123 List 456 myList … Heap Stack Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ OOP basics: memory class Node { Object data; Node next; } … main(…) { List myList = new List(); Integer i = new Integer(5); } myList first: null List i value: 5 Integer class List { private Node first; public Object getFirst() {return(first.data);} public void insertFront(Object newElement) { ... } public void insertRear(Object newElement) { ... } public void delete(Object existingElement) { ... } } Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ OOP basics: memory class Node { Object data; Node next; } … main(…) { List myList = new List(); Integer i = new Integer(5); myList.insertFront(i); } myList first List i value: 5 Integer data next: null Node class List { private Node first; public Object getFirst() {return(first.data);} public void insertFront(Object newElement) { ... } public void insertRear(Object newElement) { ... } public void delete(Object existingElement) { ... } } Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ OOP basics: memory class Node { Object data; Node next; } … main(…) { List myList = new List(); Integer i = new Integer(5); myList.insertFront(i); myList.insertRear(new Integer(8); } myList first List i value: 5 Integer data next Node next: null value: 8 class List { private Node first; public Object getFirst() {return(first.data);} public void insertFront(Object newElement) { ... } public void insertRear(Object newElement) { ... } public void delete(Object existingElement) { ... } } Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

OOP basics: encapsulation/info hiding Expose only what’s necessary Hide implementation details Unnecessary information should not be visible or modifiable Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

OOP basics: encapsulation/info hiding class MyRectangle { private double width; private double height; private Point leftTop; public double getWidth(){ return width; } public void setWidth(double width){this.width=width;} public void translate(double deltaX, double deltaY){…} } Implementation details hidden Proper class interface Implementation changed class MyRectangle { private Rectangle rect; public double getWidth(){ return rect.getWidth(); } public void setWidth(double width){ rect.setSize(width, rect.getHeight()); } public void translate(double deltaX, double deltaY){…} Class interface unchanged Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

OOP basics: reuse (inherit. & compo.) Two main forms of re-use in software eng.: Inheritance: ask whether instance of sub-class is-a(n) instance of super-class Composition: ask whether whole has-a(n) part makes sense Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

OOP basics: reuse (inherit. & compo.) List Stack StringStack +top() +push(String) +pop() +getFirst() +insertFront(Object) +insertRear(Object) +delete() +top() +push(Object) +pop() elements elements void push(Object newElement) { elements.insertFront(newElement); } void push(String newString) { elements.push(newString); } IncrStringStack String pop() { (String)(elements.pop()); } Reuse through Delegation +push(String) void push(String newString) { String top = getTop(); if (top==null || newString.compareTo(top)>0) super.push(newString); } Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

OOP basics: polymorphism Entries in this file system are either files or folders or links to other entries Files contain text Single root Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

OOP basics: polymorphism Composite Design Pattern Abstract methods needed for polymorphic use Overriden in sub-classes for specific behavior public File search(String aString) { if (!this.isBroken()) return this.linkTo.search(aString); return null; } public File search(String aString) { if (this.contents.indexOf(aString) >= 0) return this; return null; } public File search(String aString) { for (Entry anEntry : this.entries) { File aFile = anEntry.search(aString); if (aFile != null) return aFile; } return null; Example use of polymorphism Ugur Dogrusoz Computer Eng Dept, Bilkent Univ

Computer Eng Dept, Bilkent Univ References OOSE, Using UML, Patterns, and Java, 3rd Edition by Bernd Bruegge and Allen H. Dutoit, Prentice-Hall, 2010 Java Software Solutions, Foundations of Program Design by John Lewis and William Loftus, Addison-Wesley, 1998 Wikipedia, http://en.wikipedia.org Ugur Dogrusoz Computer Eng Dept, Bilkent Univ