1. BlueJ bank example with subclasses of BankAccount 2. Transparency of UML diagram for BankAccount class hierarchy

Size: px
Start display at page:

Download "1. BlueJ bank example with subclasses of BankAccount 2. Transparency of UML diagram for BankAccount class hierarchy"

Transcription

1 CS112 Lecture: Fundamental Concepts of Object-Oriented Software Development Last revised 1/13/04 Objectives: 1. To review/introduce key concepts of object-orientation: object, class, data members (class and instance), message, method (class and instance), polymorphism, and inheritance). 2. To introduce the use of object diagrams. 3. To introduce the software lifecycle. Materials: 1. BlueJ bank example with subclasses of BankAccount 2. Transparency of UML diagram for BankAccount class hierarchy I. Introduction A. We said at the outset that this course is not just about computer programming, but about a particular kind of computer programming: objectoriented programming. The purpose of today s class is to review some key concepts we have already been introduced to, and to introduce some new concepts and some key terms that we will be using throughout the semester. B. It is important to recognize that one of the key challenges we face in computer science is complexity. In fact, some writers define computer science as the science of managing complexity. Why? 1. In the fifty plus years since computers were first developed, computer technology has developed systems of dramatically increased speed and capacity. This, in turn, has led to the use of computer systems to solve ever more complex problems. Today it is possible to type just a few keystrokes and search databases literally around the world in a matter of a few seconds - a process that ultimately entails the collaboration of thousands of interconnected systems. 2. Unfortunately, as computer systems become more complex, they also become more difficult to understand and maintain. Large computer systems have passed the point where any one human being can possibly have a complete understanding of how a complete system works. As a result, large software systems are typically built and maintained by teams of scores, hundreds, or even thousands of individuals. C. To manage complexity, computer science makes use of three key concepts: modularity, abstraction, and interfaces. 1

2 1. By modularity, we mean breaking a large system up into smaller pieces - each of which may, in turn, be broken into smaller pieces, each of which may, in turn, be broken into smaller pieces... - until the individual pieces become small enough to be understood and managed by an individual or a small team of individuals. 2. By abstraction, we mean that each module in the system treats other modules it must interact with as black boxes that can be understand in terms of a small set of well-defined behaviors, but whose inner workings are irrelevant to the module that uses them. 3. The set of behaviors other modules can count on a module to exhibit is called its interface. We have it as a goal that two components that have the same interface should be interchangeable with one another, leading to notions like plug and play. Example: A familiar electrical plug is a good example of abstraction, modularity and a well-designed interface in a different realm. a) When you plug an appliance into a wall outlet, you depend on the outlet to exhibit a certain behavior (providing 115 V 60 Hz AC current), without needing to know how that current is actually generated or distributed. It may be produced by a nuclear or hydroelectric plant, or it may be produced by burning coal, oil, or natural gas. b) The appliance functions as a module that can be plugged into any standard wall outlet, and the outlet functions as a module that supplies power to any standard appliance. The appliance can be a radio, a computer, an electric shaver, a light, or whatever. c) The standard behavior of a wall outlet - including its electrical characteristics and the precise physical size and shape of the prongs - constitutes its interface. Any appliance with a plug that conform to this interface can be used with any socket that conforms to this interface. D. Over the years, computer scientists have developed a number of different approaches to achieve modularity and abstraction. Of these, the newest (and probably the most powerful) is object-orientation, or OO for short. Though OO dates back to 1967, it began to become prominent in the software world in the 1990 s, and is likely to dominate software development for many years to come. 2

3 II. Key OO Concepts Before pursuing a detailed discussion of a particular OO programming language (Java), we need to be clear in our minds about some of the fundamental concepts of OO. As you read the book for today, what concepts seemed to be crucial? - Develop list on board A. As we have already seen, the key concept in OO is the notion of an object. We have already worked with examples of objects - e.g. the various robots in the Karel J. Robot simulation. 1. Recall that an object has three essential properties. State Behavior Identity 2. At the start of the course, we developed an example of bank accounts. Today s chapter in the book developed a similar example. Certainly, an important object in the world of bank accounts is a BankAccount object. a) A bank account has a state consisting of attributes like: (1) Account number (2) Owner (3) Current balance etc. b) It has behaviors like: (1) Deposit money (2) Withdraw money (3) Calculate interest etc. c) Of course, each account would have its own identity. 3. Actually, in OO systems, objects are of three general types. (This is not meant as a rigid classification, but as a helpful way of looking at the big picture). 3

4 a) A boundary object is used to manage interaction between the program and the outside world (human user or another system). Example: What kind(s) of objects fulfilled this function in the Karel programs we were working with? (1) The window representing the robot s world that we saw on the screen was a boundary object. (2) The window containing the speed and resume/stop controls was actually a window object containing two other objects: a button object and a slider object. All were boundary objects. (3) A GUI application will always have at least one boundary object - the top-level window (frame) in which the application is displayed. (It is possible to write non-gui applications in Java, too, though we seldom will.) b) An entity object is used to represent a thing in (concrete or abstract) in the domain of the program, with methods providing operations on it. Example: What kind(s) of objects fulfilled this function in the Karel programs we were working with? (1) The object(s) representing the robot(s) (2) The objects representing the world. (We didn t work with these directly; however, the call to World.readWorld() resulted in creating the objects needed to represent a specific scenario. c) A control object is used to manage the flow of computation, using the other objects. Example: What kind(s) of objects fulfilled this function in the Karel programs we were working with? (1) The robot programs we wrote were part of a control object. 4

5 They were part of the class that contained the main method. The main method created an instance of the control object, and arranged for its run() method to be called to manage the computation. (2) In this case, it would have also been possible to have the robot object(s) do double duty (as both entity and control objects) by having our subclass of Robot include an appropriate method that could have been started from main(). (In this case, no object of the class containing main would ever have been created.) (3) It is at this point that many OO programs fudge a bit in not actually creating separate control objects - more on this later. B. A second key notion in OO is the notion of a class. Again, we have already been introduced to this concept. A class serves as a template for constructing objects. For example, in the bank account example, we would have a class BankAccount which serves as a template for creating bank account objects. 1. One difficult concept for beginners in OO is understanding the difference between a class and an object. a) Basically, when writing OO programs, we define classes. Then, when the program is running, it creates objects that belong to those classes, using new... b) Any given class is defined exactly once. But there may be many objects belonging to the class. Example: We might define a class called BankAccount, and create many instances of this class, each of which corresponds to an individual account. c) One reason for the confusion is that it is sometimes the case that we have what is called a singleton class - a class for which it only makes sense to have one object that belongs to it. Also, sometimes we may have classes which are not singletons in principle, but behave like singeletons in practice. Example: Monotheism - the belief that there is only one God - amounts to saying (if I can say this reverently) that the class God is a singleton. 5

6 Example: at any one time, there is only one person who belongs to the class PresidentOfTheUnitedStates - though over the course of the years there have, in fact, been 43 instances of this class. (In fact, any time it makes sense to use the phrase the..., there is probably such a class lurking in the background.) Examples from the robot world? The World is a singleton. It makes no sense to have more than one world object at a time. The various kinds of robots we create often behave like singletons. There is no reason - in principle - why we can t have, say, two maze escaper robots - it just happens, in many cases (like the examples we did last class), that we only create one. (And we modified the class definition to change the way the maze escaper robot behaved.) 2. To further contribute to this confusion, it is common to find that, in the case of singleton objects, we may not actually create a separate object - we may use the class as if it were an object. This is the case, for example, with the World class in the robot programs - we treat the World class as if it were an object. 3. Nonetheless, it is important to have clearly in mind that there are some fundamental differences between objects and classes. a) When we create programs, we define classes; when we run programs, we create objects. b) A class is As part of the process of defining a class, we must specify what attributes are recorded for objects of the class. A class is said to encapsulate its attributes. 4. We call these attributes data members. Example: Open up BankExample in BlueJ Look at code for class BankAccount - note how data members accountnumber, owner, and currentbalance are declared. 5. Actually, data members are of two general kinds: 6

7 a) An instance member is associated with each instance of the class, and may have a different value for each member. Example: Each bank account object will have its own value of current balance. b) A class member is associated with the class as a whole, rather than with any particular instance. Example: In today s example, we have a SavingsAccount class that pays interest periodically (while a CheckingAccount does not). We will need to record the interest rate somehow. We will likely associate this with the class as a whole, rather than with each individual account, since all accounts of the same type have the same interest rate - we don t have a different rate for each individual account. Associating such a data member with the class rather than with individual instances saves storage (one copy, rather than many), makes changing the value easier (change it just once, rather than once for each instance), and prevents inconsistencies that would arise if some copies were changed but others were not. Show declaration for interestrate in class SavingsAccount. In Java, a class member is preceded by the word static. (This specific word is actually a historical artifact from C/C++. If we were inventing a language from scratch, we might use a clearer word!) 6. Note that we didn t have any visible data members in our robot objects - though there must have been data members to keep track of things like the robot s position, orientation, and the number of beepers in its beeper bag - we just didn t have to deal with them directly. C. Objects interact by means of messages. 1. In our robot examples, the messages robots could respond to were operations like turnleft(), move(), etc. 2. In the bank account example, the act of a withdrawing money from a bank account at an ATM might be modeled by having the ATM object send a withdraw message (with a numeric argument representing the amount) to the appropriate bank account object. The account object is responsible for subtracting the amount to be withdrawn from its current balance. 7

8 D. In order to be able to respond to a message, the class involved must have as part of its definition a method for responding to that message. Example: if BankAccount objects are to be able to respond to a withdraw message, then the BankAccount class must define a withdraw(amount) method for carrying out this operation. (Note that the method name is always the same as the message name, and is followed by a parenthesized list of arguments - possibly empty.) Show code for withdraw() method in class BankAccount - note how a test is first done to ensure that there is a sufficient balance. 1. An important property of OO systems is that it is often the case that different classes of objects can respond to the same message - but in distinctive ways. This concept has a fancy name. polymorphism Example: We have already suggested that, instead of having just one kind of bank account class, we might have several - e.g. a CheckingAccount class and a SavingsAccount class. Both might be able to respond to a creditinterest message - with the checking account doing nothing and the savings account increasing the current balance by interest computed by multiplying the current balance by an interest rate. (For simplicity, we ignore the possibility of interest-bearing checking accounts, which might constitute yet another class.) This could be handled by defining a creditinterest() method in each class. a) The CheckingAccount creditinterest() method would do nothing. b) The SavingsAccount creditinterest() method would perform an actual computation. SHOW code for this method in each class 2. Actually methods are of two general types: instance methods and class methods. a) An instance method is used for an operation that performed by an individual object that is an instance of the class. Example: The withdraw(amount) and creditinterest() methods we have 8

9 been discussing are of this sort, since they deal with the individual balance of a specific account, and must therefore be sent to a specific instance of the class BankAccount. b) A class method is used for an operation that operates on the class as a whole. Example: A method to modify the interest rate for savings accounts (which, you recall, is a class data member) SHOW code for this in class SavingsAccount - note the word static again. E. In our discussion of different kinds of bank accounts, we have used at the final concept we want to review today: inheritance. 1. We have already made use of inheritance in our robot examples. 2. Note how BlueJ shows the inheritance relationship among the various classes of BankAccount. Note: a) The class BankAccount is an abstract class representing the common properties shared by all bank accounts. b) The CheckingAccount class is both a subclass of BankAccount and a superclass for OverdraftProtectedCheckingAccount. c) Each of the subclasses inherits attributes (accountnumber, owner, currentbalance etc) from the superclass, but may also have attributes of its own (e.g. an OverdraftProtectedCheckingAccount may have an attribute recording the total amount of money that is currently on loan from the bank.) Example: Create an object of class OverdraftProtectedCheckingAccount. Use inspector to show how it has inherited attributes common to all accounts plus an amount on loan attribute. d) The way that inheritance plays out can be depicted by a more complete diagram than the one that BlueJ shows. TRANSPARENCY 9

10 Bank Account accountnumber currentbalance owner deposit(amount) withdraw(amount) creditinterest() reportbalance() getaccountnumber() CheckingAccount SavingsAccount creditinterest() creditinterest() OverdraftProtected CheckingAccount amountonloan withdraw(amount) repayloan(amount) Each of the subclasses may inherit methods from its superclass, may override those methods by responding to the same message in a different way, and may have methods of its own. (E.g. the OverdraftProtectedCheckingAccount may well inherit the deposit(amount) method from BankAccount by way of CheckingAccount, but may override the withdraw(amount) method to provide overdraft protection instead of just failing, and may have a repayloan(amount) method that is invoked when the customer repays money borrowed to cover an overdraft - something that other kinds of bank accounts don t need or have. 10

11 Show in code for class OverdraftProtectedCheckingAccount- note that there is no deposit method at all, since it is inherited, while the other two are present - one because its an override, one because it is unique to this subclass. III. The Software Life-Cycle A. One last concept that we need to discuss in this discussion of What is OO? is the fact that OO programming - indeed any kind of programming - is much more than just writing code in some programming language. For those of you who have never programmed before, this is probably not much of a problem at this point, but for those of you who have done some programming, it is possible that you may have learned some bad habits that must be unlearned. (And those of you that haven t programmed before don t want to learn these bad habits!) B. The goal of programming is to produce correct, reliable, and maintainable software that meets the user s needs. Producing this kind of software requires us to follow an engineering process with several phases: 1. The Analysis Phase - determining exactly what is needed. 2. The Design Phase - determining how it will be built. 3. The Implementation (Coding) Phase - actually building it. 4. The Quality Assurance Phase - ensuring that the software we have built really does what it is supposed to do, correctly and reliably - and fixing the errors if it doesn t.. (Sometimes this is called the testing phase or the verification and validation phase. 5. The Deployment/Maintenance Phase - in which the software is used to accomplish its original purpose, and modified as necessary to keep abreast of changing requirements. C. A very serious problem in the software industry arises when the early phases (analysis and design) are given short shrift, and programmers leap right into coding. This inevitably results in software that is incorrect, unreliable, and difficult to maintain. D. Did you notice something? We have just completed an entire lecture on programming. How much actual program code did we talk about? Programming is much more than coding! 11

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

CPS122 Lecture: Defining a Class

CPS122 Lecture: Defining a Class Objectives: CPS122 Lecture: Defining a Class last revised January 14, 2016 1. To introduce structure of a Java class 2. To introduce the different kinds of Java variables (instance, class, parameter, local)

More information

Objectives: 1. Introduce the course. 2. Define programming 3. Introduce fundamental concepts of OO: object, class

Objectives: 1. Introduce the course. 2. Define programming 3. Introduce fundamental concepts of OO: object, class CS112 Lecture: Course Introduction Last revised 1/3/06 Objectives: 1. Introduce the course. 2. Define programming 3. Introduce fundamental concepts of OO: object, class Materials: 1. Questionnaire 2. Syllabi

More information

CPS122 Lecture: Course Intro; Introduction to Object-Orientation

CPS122 Lecture: Course Intro; Introduction to Object-Orientation Objectives: CPS122 Lecture: Course Intro; Introduction to Object-Orientation 1. To introduce the course requirements and procedures. 2. To introduce fundamental concepts of OO: object, class Materials:

More information

CS112 Lecture: Extending Classes and Defining Methods

CS112 Lecture: Extending Classes and Defining Methods Objectives: CS112 Lecture: Extending Classes and Defining Methods Last revised 1/9/04 1. To introduce the idea of extending existing classes to add new methods 2. To introduce overriding of inherited methods

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

More information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

CS112 Lecture: Loops

CS112 Lecture: Loops CS112 Lecture: Loops Objectives: Last revised 3/11/08 1. To introduce some while loop patterns 2. To introduce and motivate the java do.. while loop 3. To review the general form of the java for loop.

More information

CS211 Lecture: Design Quality; Cohesion and Coupling; Packages

CS211 Lecture: Design Quality; Cohesion and Coupling; Packages CS211 Lecture: Design Quality; Cohesion and Coupling; Packages Objectives: Last revised October 4, 2004 1. To introduce the notion of design quality, tradeoffs, and some principles of quality design 2.

More information

CPS122 Lecture: Introduction to Java

CPS122 Lecture: Introduction to Java CPS122 Lecture: Introduction to Java last revised 10/5/10 Objectives: 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3. To introduce

More information

1 State, objects, and abstraction

1 State, objects, and abstraction 6.01, Spring Semester, 2008 Course notes for Week 4 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.01 Introduction to EECS I Spring Semester, 2008 Course

More information

CPS352 Lecture - The Transaction Concept

CPS352 Lecture - The Transaction Concept Objectives: CPS352 Lecture - The Transaction Concept Last Revised March 3, 2017 1. To introduce the notion of a transaction and the ACID properties of a transaction 2. To introduce the notion of the state

More information

CS352 Lecture - The Transaction Concept

CS352 Lecture - The Transaction Concept CS352 Lecture - The Transaction Concept Last Revised 11/7/06 Objectives: 1. To introduce the notion of a transaction and the ACID properties of a transaction 2. To introduce the notion of the state of

More information

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Introduction to Computers and Programming Languages CS 180 Sunil Prabhakar Department of Computer Science Purdue University 1 Objectives This week we will study: The notion of hardware and software Programming

More information

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System? Page 1 of 21 Page 2 of 21 and identity. Objects are members of a class, and the attributes and behavior of an object are defined by the class definition. The Essence of Object Oriented Programming with

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

CS558 Programming Languages Winter 2013 Lecture 8

CS558 Programming Languages Winter 2013 Lecture 8 OBJECT-ORIENTED PROGRAMMING CS558 Programming Languages Winter 2013 Lecture 8 Object-oriented programs are structured in terms of objects: collections of variables ( fields ) and functions ( methods ).

More information

Inheritance (Outsource: )

Inheritance (Outsource: ) (Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,

More information

CS211 Lecture: Relationships Between Classes: Dependency, Inheritance, and Realization

CS211 Lecture: Relationships Between Classes: Dependency, Inheritance, and Realization CS211 Lecture: Relationships Between Classes: Dependency, Inheritance, and Realization Objectives: last revised July 21, 2003 1. To introduce the dependency relationship between classes 2. To review the

More information

Intro to Computer Science 2. Inheritance

Intro to Computer Science 2. Inheritance Intro to Computer Science 2 Inheritance Admin Questions? Quizzes Midterm Exam Announcement Inheritance Inheritance Specializing a class Inheritance Just as In science we have inheritance and specialization

More information

CPS122 Lecture: Detailed Design and Implementation

CPS122 Lecture: Detailed Design and Implementation CPS122 Lecture: Detailed Design and Implementation Objectives: Last revised March 3, 2017 1. To introduce the use of a complete UML class box to document the name, attributes, and methods of a class 2.

More information

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN CSSE 220 Day 15 Inheritance Check out DiscountSubclasses from SVN Discount Subclasses Work in pairs First look at my solution and understand how it works Then draw a UML diagram of it DiscountSubclasses

More information

Inheritance in Ruby. You are familiar with the idea of inheritance and how to use this in programming.

Inheritance in Ruby. You are familiar with the idea of inheritance and how to use this in programming. Inheritance in Ruby You are familiar with the idea of inheritance and how to use this in programming. In this introduction, I'll describe inheritance in Ruby from scratch. Much of this material should

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

CS112 Lecture: Introduction to Karel J. Robot

CS112 Lecture: Introduction to Karel J. Robot CS112 Lecture: Introduction to Karel J. Robot Last revised 1/17/08 Objectives: 1. To introduce Karel J. Robot as an example of an object-oriented system. 2. To explain the mechanics of writing simple Karel

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Python Programming Introduction to Object-Oriented Programming Annemarie Friedrich (anne@cis.uni-muenchen.de) Centrum für Informations- und Sprachverarbeitung LMU München Software objects

More information

OO design. Classes, Responsibilities, Collaborations (CRC) 13/9/1999 COSC

OO design. Classes, Responsibilities, Collaborations (CRC) 13/9/1999 COSC OO design Classes, Responsibilities, Collaborations (CRC) 1 bank accounts the system to be modelled: bank accounts with differing fee structures purpose: evaluate different account types with respect to

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Object-Oriented Analysis and Design Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology-Kharagpur

Object-Oriented Analysis and Design Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology-Kharagpur Object-Oriented Analysis and Design Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology-Kharagpur Lecture 06 Object-Oriented Analysis and Design Welcome

More information

CS112 Lecture: Inheritance and Polymorphism

CS112 Lecture: Inheritance and Polymorphism CS112 Lecture: Inheritance and Polymorphism Last revised 4/10/08 Objectives: 1. To review the basic concept of inheritance 2. To introduce Polymorphism. 3. To introduce the notions of abstract methods,

More information

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 18 Transaction Processing and Database Manager In the previous

More information

CPS122 Lecture: Encapsulation, Inheritance, and Polymorphism

CPS122 Lecture: Encapsulation, Inheritance, and Polymorphism Objectives: CPS122 Lecture: Encapsulation, Inheritance, and Polymorphism Last revised January 23, 2015 1. To review the basic concept of inheritance 2. To introduce Polymorphism. 3. To introduce the notions

More information

Algebraic Specifications

Algebraic Specifications Object-Oriented Design Lecture 2 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 11, 2007 Algebraic Specifications Last time I said a word about the abstraction barrier, separating the clients from the implementors.

More information

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Today we are going to talk about an important aspect of design that is reusability of design. How much our old design

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014 Abstract Classes and Methods

More information

3.1 Constructions with sets

3.1 Constructions with sets 3 Interlude on sets Sets and functions are ubiquitous in mathematics. You might have the impression that they are most strongly connected with the pure end of the subject, but this is an illusion: think

More information

Object-Oriented Analysis, Design and Implementation. Case Study Part II

Object-Oriented Analysis, Design and Implementation. Case Study Part II Object-Oriented Analysis, Design and Implementation Case Study Part II Assoc. Prof. Marenglen Biba MSc in Computer Science, UoG-UNYT Foundation Programme (C) 2010 Pearson Education, Inc. All 3-1 Further

More information

C# Programming for Developers Course Labs Contents

C# Programming for Developers Course Labs Contents C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring

More information

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas What is this class about? While this class is called Design Patterns, there are many other items of critical

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.

More information

Debugging Your Python Code: For Dummies

Debugging Your Python Code: For Dummies Debugging Your Python Code: For Dummies Tyler J. Metivier University of Connecticut Dept. of Physics May 4, 2018 1 What s the problem? It doesn t matter if you ve written 1 script or programmed a space

More information

Lecture 3: Linear Classification

Lecture 3: Linear Classification Lecture 3: Linear Classification Roger Grosse 1 Introduction Last week, we saw an example of a learning task called regression. There, the goal was to predict a scalar-valued target from a set of features.

More information

Darshan Institute of Engineering & Technology for Diploma Studies

Darshan Institute of Engineering & Technology for Diploma Studies REQUIREMENTS GATHERING AND ANALYSIS The analyst starts requirement gathering activity by collecting all information that could be useful to develop system. In practice it is very difficult to gather all

More information

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques 1 CPSC2620 Advanced Programming Spring 2003 Instructor: Dr. Shahadat Hossain 2 Today s Agenda Administrative Matters Course Information Introduction to Programming Techniques 3 Course Assessment Lectures:

More information

CHAPTER 9 DESIGN ENGINEERING. Overview

CHAPTER 9 DESIGN ENGINEERING. Overview CHAPTER 9 DESIGN ENGINEERING Overview A software design is a meaningful engineering representation of some software product that is to be built. Designers must strive to acquire a repertoire of alternative

More information

Chapter Goals. Chapter 9 Inheritance. Inheritance Hierarchies. Inheritance Hierarchies. Set of classes can form an inheritance hierarchy

Chapter Goals. Chapter 9 Inheritance. Inheritance Hierarchies. Inheritance Hierarchies. Set of classes can form an inheritance hierarchy Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package access control To

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10B Class Design By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Encapsulation Inheritance and Composition is a vs has a Polymorphism Information Hiding Public

More information

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

Object- Oriented Design with UML and Java Part I: Fundamentals Object- Oriented Design with UML and Java Part I: Fundamentals University of Colorado 1999-2002 CSCI-4448 - Object-Oriented Programming and Design These notes as free PDF files: http://www.softwarefederation.com/cs4448.html

More information

Object-Oriented Programming

Object-Oriented Programming 6.081, Spring Semester, 2007 Lecture 3 Notes 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.081 Introduction to EECS I Spring Semester, 2007 Lecture

More information

Software Development 2

Software Development 2 Software Development 2 Course Map This module introduces some of the techniques programmers use to create applications and programs. Introduction Computer Principles and Components Software Development

More information

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers 1 Critical sections and atomicity We have been seeing that sharing mutable objects between different threads is tricky We need some

More information

Inheritance (P1 2006/2007)

Inheritance (P1 2006/2007) Inheritance (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To learn about

More information

Back to ObjectLand. Contents at: Chapter 5. Questions of Interest. encapsulation. polymorphism. inheritance overriding inheritance super

Back to ObjectLand. Contents at: Chapter 5. Questions of Interest. encapsulation. polymorphism. inheritance overriding inheritance super korienekch05.qxd 11/12/01 4:06 PM Page 105 5 Back to ObjectLand Contents at: Chapter 5 #( encapsulation polymorphism inheritance overriding inheritance super learning the class hierarchy finding classes

More information

Object-Oriented Programming and Design

Object-Oriented Programming and Design C Sc 335 Course Overview Object-Oriented Programming and Design Rick Mercer Major Topics in C Sc 335 1. Java 2. Object-Oriented Programming 3. Object-Oriented Design 4. Technology 5. Object-Oriented Principles

More information

Enriching Behavioral Subtyping

Enriching Behavioral Subtyping Enriching Behavioral Subtyping Neelam Soundarajan and Stephen Fridella Computer and Information Science The Ohio State University Columbus, OH 43210 e-mail: {neelam,fridella}@cis.ohio-state.edu June 7,

More information

Characterizing your Objects

Characterizing your Objects Characterizing your Objects Reprinted from the Feb 1992 issue of The Smalltalk Report Vol. 2, No. 5 By: Rebecca J. Wirfs-Brock In this column I ll describe some vocabulary I find useful to characterize

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java

Object-Oriented Software Engineering Practical Software Development using UML and Java Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes Lecture 5 5.1 What is UML? The Unified Modelling Language is a standard graphical

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

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

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

DATABASE TRANSACTIONS. CS121: Relational Databases Fall 2017 Lecture 25

DATABASE TRANSACTIONS. CS121: Relational Databases Fall 2017 Lecture 25 DATABASE TRANSACTIONS CS121: Relational Databases Fall 2017 Lecture 25 Database Transactions 2 Many situations where a sequence of database operations must be treated as a single unit A combination of

More information

Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13

Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about inheritance To understand how

More information

Introduction to UML What is UML? Motivations for UML Types of UML diagrams UML syntax Descriptions of the various diagram types Rational Rose (IBM.. M

Introduction to UML What is UML? Motivations for UML Types of UML diagrams UML syntax Descriptions of the various diagram types Rational Rose (IBM.. M Introduction to UML Part I 1 What is UML? Unified Modeling Language, a standard language for designing and documenting a system in an object- oriented manner. It s a language by which technical architects

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation Outline Problem: Create, read in and print out four sets of student grades Setting up the problem Breaking

More information

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT Object Oriented Programming Examiner s Report March 2017 A1. a) Explain what is meant by the following terms:

More information

CPS221 Lecture: Threads

CPS221 Lecture: Threads Objectives CPS221 Lecture: Threads 1. To introduce threads in the context of processes 2. To introduce UML Activity Diagrams last revised 9/5/12 Materials: 1. Diagram showing state of memory for a process

More information

SOFTWARE ENGINEERING Prof.N.L.Sarda Computer Science & Engineering IIT Bombay. Lecture #10 Process Modelling DFD, Function Decomp (Part 2)

SOFTWARE ENGINEERING Prof.N.L.Sarda Computer Science & Engineering IIT Bombay. Lecture #10 Process Modelling DFD, Function Decomp (Part 2) SOFTWARE ENGINEERING Prof.N.L.Sarda Computer Science & Engineering IIT Bombay Lecture #10 Process Modelling DFD, Function Decomp (Part 2) Let us continue with the data modeling topic. So far we have seen

More information

1st Semester MTCE 601A COMPUTER SYSTEM SOFTWARE

1st Semester MTCE 601A COMPUTER SYSTEM SOFTWARE 1st Semester MTCE 601A COMPUTER SYSTEM SOFTWARE LECTURE-1 Syllabus Introduction 1.1 Introduction to Object Oriented 1.2 Introduction to UML 1.3 Software Process and OOA&D 1.4 Component and CBSD 1.5 Patterns

More information

Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 1 Terminology 1 2 Class Hierarchy Diagrams 2 2.1 An Example: Animals...................................

More information

Storing Data in Objects

Storing Data in Objects Storing Data in Objects Rob Miles Department of Computer Science 28d 08120 Programming 2 Objects and Items I have said for some time that you use objects to represent things in your problem Objects equate

More information

CPS122 Lecture: Cohesion and Coupling. 1. To introduce cohesion and coupling as criteria for evaluating designs

CPS122 Lecture: Cohesion and Coupling. 1. To introduce cohesion and coupling as criteria for evaluating designs CPS122 Lecture: Cohesion and Coupling Objectives: Last revised March 27, 2015 1. To introduce cohesion and coupling as criteria for evaluating designs Materials: 1. Cohesion/coupling worksheet + projectable

More information

step is to see how C++ implements type polymorphism, and this Exploration starts you on that journey.

step is to see how C++ implements type polymorphism, and this Exploration starts you on that journey. EXPLORATION 36 Virtual Functions Deriving classes is fun, but there s not a lot you can do with them at least, not yet. The next step is to see how C++ implements type polymorphism, and this Exploration

More information

CSE 143. "Class Relationships" Class Relationships and Inheritance. A Different Relationship. Has-a vs. Is-a. Hierarchies of Organization

CSE 143. Class Relationships Class Relationships and Inheritance. A Different Relationship. Has-a vs. Is-a. Hierarchies of Organization Class Relationships and Inheritance [Chapter 8, pp.343-354] "Class Relationships" is the title of Chapter 8 One class may include another as a member variable Date" used inside "Performance" Called a "has-a"

More information

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

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

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

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

CS 215 Software Design Sample midterm solutions

CS 215 Software Design Sample midterm solutions Software Design Sample midterm solutions 1. The administration at Happy Valley School District is redesigning the software that manages information about its students. It has identified an abstract class

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

Introduction to Inheritance

Introduction to Inheritance Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits

More information

COPYRIGHTED MATERIAL. Dipping Your Toe into Python. Part I. Chapter 1: Programming Basics and Strings. Chapter 2: Numbers and Operators

COPYRIGHTED MATERIAL. Dipping Your Toe into Python. Part I. Chapter 1: Programming Basics and Strings. Chapter 2: Numbers and Operators Part I Dipping Your Toe into Python Chapter 1: Programming Basics and Strings Chapter 2: Numbers and Operators Chapter 3: Variables Names for Values COPYRIGHTED MATERIAL 1 Programming Basics and Strings

More information

Programming via Java Subclasses

Programming via Java Subclasses Programming via Java Subclasses Every class in Java is built from another Java class. The new class is called a subclass of the other class from which it is built. A subclass inherits all the instance

More information

Introduction to Unified Modelling Language (UML)

Introduction to Unified Modelling Language (UML) IMPORTANT NOTICE TO STUDENTS These slides are NOT to be used as a replacement for student notes. These slides are sometimes vague and incomplete on purpose to spark a class discussion Introduction to Unified

More information

Agenda: Notes on Chapter 3. Create a class with constructors and methods.

Agenda: Notes on Chapter 3. Create a class with constructors and methods. Bell Work 9/19/16: How would you call the default constructor for a class called BankAccount? Agenda: Notes on Chapter 3. Create a class with constructors and methods. Objectives: To become familiar with

More information

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 Object Fundamentals Part Two Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

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

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized

More information

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN NOTES ON OBJECT-ORIENTED MODELING AND DESIGN Stephen W. Clyde Brigham Young University Provo, UT 86402 Abstract: A review of the Object Modeling Technique (OMT) is presented. OMT is an object-oriented

More information

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson January 13, 2005 January 18, 2005 1 of 38 Lecture Goals Introduce the basic concepts of object-oriented analysis/design/programming

More information

COMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation

COMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation COMP-202 Unit 8: Defining Your Own Classes CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation Defining Our Own Classes (1) So far, we have been creating

More information

Object-Oriented Technology. Rick Mercer

Object-Oriented Technology. Rick Mercer Object-Oriented Technology Rick Mercer 1 Object-Oriented Technology: Outline Consider a few ways in which data is protected from careless modification Mention the key features object-oriented style of

More information

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

More information

Last Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns

Last Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns Lecture 26: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Last Lecture Design Patterns Background and Core Concepts Examples Singleton,

More information

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

(Refer Slide Time 6:48)

(Refer Slide Time 6:48) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about

More information

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information