The object-oriented approach goes a step further by providing tools for the programmer to represent elements in the problem space.

Similar documents
Object Oriented Software Design

1: Introduction to Object (1)

Introduction to Objects

Chapter 1. Introduction to Objects. C++ Object Oriented Programming Pei-yih Ting NTOUCS

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Object-Oriented Programming

Goals of the Lecture OO Programming Principles

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

JAVA: A Primer. By: Amrita Rajagopal

OBJECT ORİENTATİON ENCAPSULATİON

COURSE 2 DESIGN PATTERNS

What are the characteristics of Object Oriented programming language?

Introduction to Object-Oriented Programming

1. Write two major differences between Object-oriented programming and procedural programming?

Introduction to Java and OOP. Hendrik Speleers

Java Object Oriented Design. CSC207 Fall 2014

Object-Oriented Concepts and Design Principles

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language


Lecture Notes on Programming Languages

QUIZ. How could we disable the automatic creation of copyconstructors

Object-Oriented Programming, Iouliia Skliarova

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

CPS 506 Comparative Programming Languages. Programming Language

QUIZ. How could we disable the automatic creation of copyconstructors

2. The object-oriented paradigm!

Chapter 9 :: Data Abstraction and Object Orientation

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

Concepts of Programming Languages

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

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

Strict Inheritance. Object-Oriented Programming Winter

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

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Introduction. Object-Oriented Programming Spring 2015

Data Abstraction. Hwansoo Han

Chapter 10 :: Data Abstraction and Object Orientation

An Introduction to Object Orientation

Software Architecture (Lesson 2) Object-Oriented Paradigm (1)

Java 8 Programming for OO Experienced Developers

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

C++ Inheritance and Encapsulation

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 5 Object-Oriented Programming

QUIZ. What is wrong with this code that uses default arguments?

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

INHERITANCE: EXTENDING CLASSES

Inheritance, polymorphism, interfaces

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

ECE 3574: Dynamic Polymorphism using Inheritance

Lecturer: William W.Y. Hsu. Programming Languages

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

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

Inheritance & Polymorphism. Object-Oriented Programming Spring 2015

This wouldn t work without the previous declaration of X. This wouldn t work without the previous declaration of y

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

Programming in C# Inheritance and Polymorphism

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

CS-202 Introduction to Object Oriented Programming

CHAPTER 5 GENERAL OOP CONCEPTS

CSE 307: Principles of Programming Languages

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

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

VIRTUAL FUNCTIONS Chapter 10

Virtual functions concepts

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

Example: Count of Points

7. C++ Class and Object

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

ITI Introduction to Computing II

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Chapter 14 Abstract Classes and Interfaces

Short Notes of CS201

15: Polymorphism & Virtual Functions

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

Inheritance, Polymorphism, and Interfaces

Inheritance Motivation

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University

Strict Inheritance. Object-Oriented Programming Spring 2008

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Exercise: Singleton 1

CS201 - Introduction to Programming Glossary By

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

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

Inheritance and Interfaces

7: Polymorphism. Interface & Implementation. Hands-on Java Seminar 2000 Bruce Eckel page 1. A Circle.

G Programming Languages - Fall 2012

Programming II (CS300)

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Object-Oriented Programming

What about Object-Oriented Languages?

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

Example: Count of Points

Transcription:

1

All programming languages provide abstractions. Assembly language is a small abstraction of the underlying machine. Many imperative languages (FORTRAN, BASIC, and C) are abstractions of assembly language. Their primary abstractions still requires you to think in terms of the structure of the computer rather than the structure of the problem that you are trying to solve. The alternative to modeling the machine is to model the problem. LIST : All problems are ultimately lists. APL : All problems are algorithmic. PROLOG casts all problems into chains of decisions. Each of these approaches is a good solution to the particular class of problem. The object-oriented approach goes a step further by providing tools for the programmer to represent elements in the problem space. 2

Five basic characteristics of Smalltalk (the first successful objectoriented language) Everything is an object. A problem is a bunch 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 particular type can receive the same messages. Booch described an object as followings. An object has state, behavior and identity. 3

Creating abstract data types (classes) is a fundamental concept in object-oriented programming. Simula-67, the first object-oriented language, introduces the keyword class for creating a new type in a program. Abstract data types work almost exactly like built-in types. Virtually, all object-oriented programming languages use the class keyword. A class describes a set of objects that have identical characteristics (data elements) and behaviors (functionality). There must be a way to make a request of the object so that it will do something. The requests you can make of an object are defined by its interface. 4

The interface establishes what requests you can make for a particular object. There must be code somewhere to satisfy that request. Along with the hidden data, comprises the implementation. A simple example of a light bulb Light lt = new Light (); lt.on (); The name of the type/class is Light. The name of this particular Light object is lt. The requests that you can make of a Light object are to turn it on, turn if off, make it brighter, or make it dimmer. 5

One of the best ways to think about objects is as service providers. For example, a bookkeeping program Objects that contain pre-defined bookeeping input screens Objects that perform bookeeping calculations Object that handles printing of checks and invoices. Thinking of an object as a service provider helps to improve the cohesiveness of the object. One problem people have when designing objects is cramming too much functionality into one object. In a good object-oriented design, each object does one thing well, but doesn t try to do too much. Treating objects as service providers is useful when someone else is trying to understand your code or reuse an object. 6

It is helpful to break up the playing field into class creators (those who create new data types) and client programmers (the class consumers who use the data types in their applications). The goal of the client programmer is to collect a toolbox full of classes to use for rapid application development. The goal of the class creator is to build a class that exposes only what s necessary to the client programmer and keeps everything else hidden. Why hiding? The client programmer cannot access it. The class creator can change the hidden portion at will without worrying about the impact on anyone else. The concept of implementation hiding cannot be overemphasized. 7

The first reason for access control is to keep client programmers hands off portions they shouldn t touch. This is actually a service to users because they can easily see what s important to them and what they can ignore. The second reason for access control is to allow the library designer to change the internal workings of the class without worrying about how it will affect the client programmer. Java uses three explicit keywords to set the boundaries in a class: public, private, and protected. public: the following element is available to everyone. private: no one can access that element except the creator. protected: all inheriting class has access to protected members. 8

Once a class has been created and tested, it should (ideally) represent a useful unit of code. Code reuse is one of the greatest advantage that object-oriented programming language provide. The simplest way to reuse a class is to just use an object of that class directly. You can also place an object of that class inside a new class. -> creating a member object. Because you are composing a new class from existing classes, this concept is called composition. Composition is often referred to as a has-a relationship. 9

It is nicer if we can take the existing class, clone it, and then make additions and modifications to the clone. A base type contains all of the characteristics and behaviors that are shared among the types derived from it. A trash-recycling machine the class shape class 10

A new inherited type contains not only all the members of the existing type (although the private ones are hidden away and inaccessible), but more importantly it duplicates the interface of the base class. The derived class is the same type as the base class. In the previous example, a circle is a shape. You have two ways to differentiate your new derived class from the original base class. (1) You simply add brand new methods to the derived class. (2) The second and more important way to differentiate your new class is to change the behavior of an existing base-class method. This is referred to as overriding that method. 11

(1) (2) 12

is-a relationship A derived type is exactly the same type as the base class since it has exactly the same interface. This can be thought of as pure substitution. A circle is a shape. is-like-a relationship There are times when you must add new interface elements to a derived type, thus extending the interface and creating a new type. The new type has the interface of the old type but it also contains other methods. The heat pump is-like-an air conditioner. 13

For example, the heat pump is-like-an air conditioner, but it can do more. Once you see this design it becomes clear that the base class cooling sy stem is not general enough, and should be renamed to temperature c ontrol system. However, this diagram is an example of what can happe n with design in the real world. 14

When dealing with type hierarchies, you often want to treat an object not as the specific type that it is, but instead as its base type. This ability to easily extend a design by deriving new subtypes is one of the essential ways to encapsulate change. If a method is going to tell a generic shape to draw itself, or a generic vehicle to steer, or a generic bird to move, the compiler cannot know at compile time precisely what piece of code will be executed. 15

Object-oriented languages use the concept of late binding. When you send a message to an object, the code being called isn t determined until run time. void dostuff(shape s) { s.erase(); //... s.draw(); } Circle c = new Circle(); Triangle t = new Triangle(); Line l = new Line(); dostuff(c); dostuff(t); dostuff(l); 16

Often in a design, you want the base class to present only an interface for its derived classes. This is accomplished by making that class abstract by using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents it. You can also use the abstract keyword to describe a method that hasn t been implemented yet. The interface keyword takes the concept of an abstract class one step further by preventing any method definitions at all. 17

Technically, OOP is just about abstract data typing, inheritance, and polymorphism, but other issues can be at least as important. Other issues include: Object creation, use & lifetimes Collections and iterators The singly rooted hierarchy Downcasting vs. templates/generics Ensuring proper cleanup Garbage collectors vs. efficiency and flexibility Exception handling: dealing with errors Concurrency 18

(1) Chapter 1 을 5 쪽이내로한글로요약하시오. (2) Java 와 C++ 언어의차이점을설명하시오. Java 언어에서만제공하는기능또는개념 C++ 언어에서만제공하는기능또는개념 제출마감일 : 3 월 17 일 ( 월요일 ) 수업시간까지 주의사항 반드시손으로작성하여제출 ( 워드프로세서사용금지 ) 19