Computer Science 111 Fundamentals of Programming I Introduction to Object-Based Programming.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
1 Chapter Eight Designing Libraries. 2 Programming Complexity As long as we continue to solve problems of ever-increasing sophistication, the process.
Page 1 of 26 Javascript/Jscript Ch 7,8,9,10 Vadim Parizher Computer Science Department California State University, Northridge Spring 2003 Slides from.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UML for design: Class Diagrams.
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Lecture 4 Class Responsibility Collaboration Cards
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 2 Tariq Aziz and Kevin Jones.
1 Basic Object Oriented Concepts Overview l What is Object-Orientation about? l What is an Object? l What is a Class? l Constructing Objects from Classes.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 1 Program Design
C++ fundamentals.
Chapter 9 Domain Models 1CS6359 Fall 2012 John Cole.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Computer Science 111 Fundamentals of Programming I Introduction to Programmer-Defined Classes.
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts.
Module 7: Object-Oriented Programming in Visual Basic .NET
Chapter 2: Objects and Primitive Data Classes and Objects String, Random, Math, NumberFormat, DecimalFormat and Wrapper Classes.
Computer Science 111 Fundamentals of Programming I More Data Modeling.
MOM! Phineas and Ferb are … Aims:
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
ACO 101 Instantiating Graphic Objects. Review: 4 Phases to the Development Lifecycle Inception (Analysis & Design) – Business Requirements Business Analyst.
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
Design Model Lecture p6 T120B pavasario sem.
Chapter 1: Object Oriented Paradigm. 1.1 Data Abstraction and Encapsulation OOP allows programmer to – separate the details that are important to the.
Chapter 6 Methods: A Deeper Look. Objectives In this chapter you will learn: How static methods and fields are associated with an entire class rather.
Chapter 17 – Object- Oriented Design. Chapter Goals To learn about the software life cycle To learn about the software life cycle To learn how to discover.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Fundamentals Usman Ependi UBD
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 10/15/04CS150 Introduction to Computer Science 1 Reading from and Writing to Files Part 2.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 3 Implementing Classes
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
WELCOME TO OUR PRESENTATION UNIFIED MODELING LANGUAGE (UML)
MAITRAYEE MUKERJI Object Oriented Programming in C++
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Object Oriented Programming
Fundamentals of Programming I Introduction to Object-Based Programming
Topics Graphical User Interfaces Using the tkinter Module
Classes and OOP.
Object-Oriented Analysis and Design
Use Case Model.
Computer Science 111 Fundamentals of Programming I
Java Programming: From Problem Analysis to Program Design,
Chapter Three - Implementing Classes
C# Object Oriented Programming Concepts
Chapter 4: Writing classes
Dry run Fix Random Numbers
Computer Science 111 Fundamentals of Programming I
Fundamentals of Programming I Commonly Used Methods More Modeling
Topics Graphical User Interfaces Using the tkinter Module
Computer Science I: Get out your notes.
Handout-2(a) Basic Object Oriented Concepts
Presentation transcript:

Computer Science 111 Fundamentals of Programming I Introduction to Object-Based Programming

Organizing Programs As problems get more interesting and difficult, solutions (programs) become more complex How do we control this complexity, so as to keep it manageable and not be overwhelmed by it?

One Answer: Abstraction Find a way of hiding complex details in a new unit of code, thereby treating many things as one thing Examples: A function - hides an algorithm in a single entity ( math.sqrt, reply ) A module - hides a set of functions in a single entity ( random, math ) A data structure - hides a collection of data in a single entity (list, dictionary)

Using Abstractions A program becomes a set of cooperating modules, functions, and data structures Each program component is simple enough to be understood immediately and tested independently When interactions among components become complex, package these in a new abstraction (another function, data structure, or module)

Another Abstraction: Objects An object combines data and operations into a single unit An object is like an intelligent agent that knows what to do with its own data Examples: –A GUI window –A command button, a data entry field, a drop-down menu –A point, circle, rectangle, or polygon –An image, a pixel, a sound clip, or a network connection –Actually, any Python data value (lists, strings, integers, etc.)

myrtle = Turtle() yertle = Turtle() p = Point(50, 50) c1 = Circle(p, 50) c2 = Circle(p, 30) Turtle, Point, and Circle are classes myrtle, yertle, p, c1, and c2 refer to objects or instances of these classes A class defines the behavior of a set of objects Creating Objects from Classes CirclePoint c1c2p Turtle myrtleyertle

myrtle = Turtle() p = Point(50, 50) c1 = Circle(p, 50) c2 = Circle(p, 30) c1.draw(myrtle), c2.draw(myrtle) print(c1.getRadius(), c2.getRadius()) We get an object to do things by running methods A method is like a function: it hides an algorithm for performing a task Getting Objects to Do Things draw and getRadius are methods

Objects: State and Behavior An object has two essential features: 1.A behavior, as defined by the set of methods it recognizes 2.A state, as defined by the data that it contains Object-based programming models the state and behavior of real-world objects with computational objects

Modeling Closely study the relevant attributes and behavior of the objects in the system being modeled Design and code computational objects that reflect these attributes and behavior

Example: Dice Dice are used in many games of chance (backgammon, monopoly, etc.) A single die is a cube whose sides represent the numbers 1-6 When a die is rolled, the number selected is the one on the side that happens to be facing up

State and Behavior of a Die The state of a die is the number currently visible on its top face; its initial state is a randomly chosen number from 1 through 6 Behavior: –Roll the die to reset its state to a randomly chosen number from 1 through 6 –Get the die’s current number Verbs in the description indicate behavior; nouns indicate attributes (state)

Die()# Returns a new Die object roll() # Resets the die's value getValue() # Returns the die's value The Die Class: External View The set of a class’s methods is also called its interface The user of class only needs to know its interface

from die import Die # Instantiate a pair of dice d1 = Die() d2 = Die() # Roll them and view them 100 times for x in range(100): d1.roll() d2.roll() print(d1.getValue(), d2.getValue()) Using Some Dice

Object Instantiation <variable> = <class name>(<arguments>) Syntax of object instantiation: from die import Die # Instantiate a pair of dice d1 = Die() d2 = Die() # Roll them and view them 100 times for x in range(100): d1.roll() d2.roll() print(d1.getValue(), d2.getValue())

Calling a Method <object>.<method name>(<arguments>) Syntax of a method call: from die import Die # Instantiate a pair of dice d1 = Die() d2 = Die() # Roll them and view them 100 times for x in range(100): d1.roll() d2.roll() print(d1.getValue(), d2.getValue())

Using Dice: The Game of Craps Played with a pair of dice An initial roll of 7 or 11 wins An initial roll of 2, 3, or 12 loses Any subsequent roll of 7 loses Any subsequent roll that equals the initial roll wins

Example: Checking Accounts A checking account holds a balance We can make deposits or withdrawals Interest checking allows for a periodic computation of interest, which is added to the balance

State and Behavior of a Checking Account The state of an account is –The owner’s name –The owner’s PIN –The current balance The interest rate is common to all accounts Behavior: –Make a deposit of a given amount –Make a withdrawal of a given amout –Compute the interest –Get the current balance

CheckingAccount(name, pin, bal) # Returns a new object getBalance() # Returns the current balance deposit(amount) # Makes a deposit withdraw(amount) # Makes a withdrawal computeInterest() # Computes the interest and # deposits it The Interface of the CheckingAccount Class

from bank import CheckingAccount # Instantiate an account account = CheckingAccount('Ken', '3322', ) # Do some things with it print(account.getBalance()) account.deposit(500.00) print(account.getBalance()) account.withdraw( ) print(account.getBalance()) account.computeInterest() print(account.getBalance()) Using a Checking Account

from bank import CheckingAccount # Instantiate two acounts jackAccount = CheckingAccount('Jack', '3322', ) jillAccount = CheckingAccount('Jill', '3323', ) jackAccount.deposit(50.00) jillAccount.withdraw(100) Each Account Has Its Own State The states of distinct objects can vary, but the methods that apply to them are the same

Object-Based Programming: Summary Study the system of objects that you’re modeling to discover the relevant attributes and behavior For each type of object, choose a class whose methods realize its behavior Write a short tester program that creates some objects and runs their methods Use the objects in your application

For Wednesday Image Processing in Chapter 7