Object-Oriented (Component-Based) Program Design Process

Slides:



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

Written by: Dr. JJ Shepherd
Inheritance Inheritance Reserved word protected Reserved word super
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
High-Level Programming Languages
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Object Oriented Paradigm Programming Paradigms En Mohd Norafizal A.Aziz.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
OOP Languages: Java vs C++
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
1Object-Oriented Program Development Using C++ Computer Science and Programming Languages Computers are ubiquitous Computer literacy is essential Computer.
Introduction to Object-oriented programming and software development Lecture 1.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Java Classes Using Java Classes Introduction to UML.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Written by: Dr. JJ Shepherd
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
OOP Basics Classes & Methods (c) IDMS/SQL News
Chapter 3 Implementing Classes
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Comp1004: Building Better Objects II Encapsulation and Constructors.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Creating and Using Objects, Exceptions, Strings
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Concepts of Object Oriented Programming
Classes and OOP.
About the Presentations
Service-Oriented Computing -- Service Provider and Application Builder
OOP’S Concepts in C#.Net
Computer Programming.
Java LESSON 7 Objects, Part 1
PROGRAMMING PARADIGMS
Object-Oriented Programming
Encapsulation and Constructors
CS2011 Introduction to Programming I Objects and Classes
Object-Oriented Programming
Session 2: Introduction to Object Oriented Programming
Object-Oriented Programming
Programming Languages and Paradigms
Introduction to Object-Oriented Programming
Lecture 18 Making C# Objects
C++ Object Oriented 1.
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Object-Oriented (Component-Based) Program Design Process CSE 101 Yinong Chen

Table of Contents 1 Paradigms of Computing & Languages 2 Design Process of an OO Program 3 Class and Objects from a Class 4 Implement the Solution in C# 5 Interface: Console vs. GUI

Granularity of Abstraction Granularity Level Programming-in-the-large Service-Oriented Programming Java, C#, VPL Logic Programming e.g. Prolog Functional Programming e.g. LISP/Scheme Object-Oriented Programming C++, Java, C# Component-Based Programming Alice, LabView C++, Java, C# Procedural Programming Pascal, C Imperative Programming Assembly, Algo, FORTRAN 50s 60s 70s 80s 90s 00s 10s Time Programming-in-the-small 22 September 201822 September 2018

Object-Oriented Paradigm What is a Program? Program Algorithm Data Data Process (steps) of data manipulation Objects of the manipulation Emphasis: Imperative / Procedural Paradigms Emphasis: Object-Oriented Paradigm

Imperative Paradigm Fully specified and fully controlled manipulation of named data in a step-wise fashion. Developed as abstractions of von Neumann machine (stored program concept). Programs are algorithmic in nature: do this, then that, then repeat this ten times -- focuses on how rather than what. Why popular Performance – match the machine Culture – reading manuals

Features of Object-Oriented Programming Data are organized in Object/Class: Operations are part of an object for manipulating the data in the object; Abstract data type (class): Encapsulation of state in an object that can only be accessed through operations defined on them. Clean interface -- public and private components. Inheritance: extending a class by keeping the unchanged parts. Supports code reuse. Classes are organized in hierarchies. Dynamic memory allocation and de-allocation Dynamic binding Polymorphism

Traditional Software Design Process Software development What is the need of users Requirement analysis What needs to be created to meet the user’s need? Specification How to do it? (Algorithms) Alternative designs Implementation (coding) How to code it? (programming ) Testing / Evaluation Run it in a virtual environment Deployment Put it in the real environment 22 September 201822 September 2018

Object-Oriented / Component-Based Software Development Bricks and Tiles traditional Component- based 22 September 201822 September 2018

Object-Oriented and Service-Oriented Software Development Requirement analysis Programmers Programmers Services development Object-oriented development Problem decomposition Service repository Services testing Component library Object testing Application builder Application building Testing To be discussed later Deployment

Travel Preparation Problem Definition (Requirements) Input: The numbers of days to travel; The country name; The local temperature in Celsius; Output: The amount of local currency needed The local temperature in Fahrenheit

Problem Decomposition Main class Enter numbers of days to travel; Enter the country name Make use of other classes to perform computation; Print output; days amount in USD Fahrenheit Celsius Amount in local currency Hotel cost in USD; Rental car cost in USD; Meal cost in USD; Total cost Convert Celsius to Fahrenheit; Convert Fahrenheit to Celsius; amount in USD TemperatureConversion class myCost class Convert USD amount into local currency amount; CurrencyConversion class

Class Members A class consists of a list of members Each member can be a data member, or called a variable a function member, or called a method Function members Constructor: is a function member that has the same name as the class name. It is used to Initialize the data members in the class Pass values into the class, if the values will be used by multiple function members Other function members are used Manipulate data members; Provide reusable functions for other classes to call;

Class versus Objects A class is a structural design, or a called blueprint A member can be private or public private members can be accessed in the class only Public members can also be accessed outside the class Static member: If static keyword is used, the member can be accessed without instantiation: className.memberName A class can be used to instantiate one or more objects ClassName refName = new ClassName(); refName.memberName to access the member A set of library functions (methods) are grouped in one class; A group of classes are organized as a namespace

using System; class TravelPreparation { static void Main(string[] args) { // The main method Console.WriteLine("Please enter the number of days you will travel"); String str = Console.ReadLine(); // read a string of characters Int32 daysToStay= Convert.ToInt32(str); // Convert string to integer myCost usdObject = new myCost(daysToStay); // Create an object int usdCash = usdObject.total(); // Call a method in the object Console.WriteLine("Please enter the country name you will travel to"); String country = Console.ReadLine(); CurrencyConversion exchange = new CurrencyConversion(); Double AmountLocal = exchange.usdToLocalCurrency(country, usdCash); Console.WriteLine("The amount of local currency is: " + AmountLocal); Console.WriteLine("Please enter the temperature in Celsius"); str = Console.ReadLine(); Int32 celsius = Convert.ToInt32(str); TemperatureConversion c2f = new TemperatureConversion(); Int32 fahrenheit = c2f.getFahrenheit(celsius); Console.WriteLine("The local temperature in Fahrenheit is: " + fahrenheit); } Main Class is the class with the Main method

TemperatureConversion c2f = new TemperatureConversion(); Class name Return type Method name No constructor class TemperatureConversion { public Int32 getFahrenheit(Int32 c) Double f = c * 9 / 5 + 32; return Convert.ToInt32(f); } public Int32 getCelsius(Int32 f) Double c = (f - 32) * 5 / 9; return Convert.ToInt32(c); Method 1 Parameter passing into function directly Methods2 TemperatureConversion c2f = new TemperatureConversion(); Int32 fahrenheit = c2f.getFahrenheit(celsius);

Reference to an Object TemperatureConversion c2f = new TemperatureConversion(); Int32 fahrenheit = c2f.getFahrenheit(celsius); class TemperatureConversion { public Int32 getFahrenheit(Int32 c) Double f = c * 9 / 5 + 32; return Convert.ToInt32(f); } public Int32 getCelsius(Int32 f) Double c = (f - 32) * 5 / 9; return Convert.ToInt32(c); 42F1D761C c2f 42F1D761C c2f.getFahrenheit(23); c2f. getCelsius(98);

class myCost { private Int32 days; public myCost(Int32 daysToStay) { days = daysToStay; } private Int32 hotel() { return 100 * days; private Int32 rentalCar() { return 30 * days; private Int32 meals() { return 20 * days; public Int32 total() { return hotel() + rentalCar() + meals(); Constructor: is a method that has the same name as the class. Allow to pass a value into the class and used by all methods Data member The value is provided when an object is created. myCost usdObject = new myCost(daysToStay); int usdCash = usdObject.total();

class CurrencyConversion { public Double usdToLocalCurrency(String country, Int32 usdAmount) { switch(country) { case "Japan": return usdAmount * 117; case "EU": return usdAmount * 0.71; case "Hong Kong": return usdAmount * 7.7; case "UK": return usdAmount * 0.49; case "South Africa": return usdAmount * 6.8; default: return -1; } This class does not need to have a constructor: It has no data member; The parameter is passed to the function member, instead of into the class for all member functions to use. There is one function member only in this class. If there would be more methods and all methods use the same parameters, we would want to pass the parameters into the class, instead of into individual methods.

HW 1: Question 1 Anti Block System and Traction Control of a Car Main class Get sensor values from Sensors class; Compare sensor values Take action by calling Actuator class; Power level velocities Brake force level Read wheel speed; Read body Speed; Control break Control engine make wheelDiameter; mpg; tankSize baseRental Sensors class Actuators class Cars class

class Program { static void Main(string[] args) Console.WriteLine("Please enter the make of the car"); String make = Console.ReadLine(); // read a string, e.g. bmw Console.WriteLine("Please enter the miles to drive"); String str = Console.ReadLine(); // read a string, e.g, 1000 Int32 miles = Convert.ToInt32(str); Cars cRef = new Cars(make); // create an object of Cars Double cost = cRef.rentalCost(miles); Console.WriteLine("The cost of driving is " + cost); Sensors sRef = new Sensors(cRef); // create an object of Sensors Actuators aRef = new Actuators(); // create an object of Actuators for (Int32 i = miles; i > 0; i= i - 10) { Double wv = sRef.wheel_velocity(); Double bv = sRef.body_velocity(); //Console.WriteLine("wv = {0} bv = {1}", wv, bv); if (Math.Abs(bv - wv) < 1) // 1 is the tolerance Console.WriteLine("no action"); else if (bv > wv) aRef.brakeForce(); else aRef.enginPower(); }

class Cars { private Double wheelDiameter; private Double mpg; // miles per galon private Double tank; private Double baseRental; public Double rentalCost(Int32 m) { return baseRental + (m / mpg) * 3.0; // $3/gal } public Cars(String make) { if (make == "bmw") { wheelDiameter = 17; mpg = 20; // miles per gallon tank = 25; // gallons of gasoline baseRental = 100; else { wheelDiameter = 15; mpg = 24; baseRental = 50;

class Sensors { private Double wheel_diameter; // inches Random randomizer; public Sensors(Cars carRef) wheel_diameter = carRef.getDiameter(); randomizer = new Random(); } public Double wheel_velocity() { Double mile_inch = 63360.0; // inches per mile Double pi = Math.PI; Double rps = randomizer.Next(25); Double wv = (pi * wheel_diameter * rps * 3600) / mile_inch; return wv; public Double body_velocity() { Int32 bv = randomizer.Next(70); return bv;

class Actuators { public void brakeForce() Console.WriteLine("reduce brake force!"); } public void enginPower() Console.WriteLine("reduce engine power level!");

Console Interface versus Graphic User Interface