XuanTung Hoang 1 Something to discuss Feedbacks on Midterm Exam Final exam and term project  Final exam requires solid knowledge/skills in Java  Be more.

Slides:



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

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Chapter 41 Defining Classes and Methods Chapter 4.
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
CS 106 Introduction to Computer Science I 03 / 23 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
ASP.NET Programming with C# and SQL Server First Edition
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
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.
Object Oriented Software Development
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Chapter 4 Objects and Classes.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
COSC 1P03 Data Structures and Abstraction 1.1 File Processing You've achieved success in your field when you don't know whether what you're doing is work.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Slide 1 Chapter 6 Structures and Classes. Slide 2 Learning Objectives  Structures  Structure types  Structures as function arguments  Initializing.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Chapter 0: Introduction
Objects as a programming concept
Classes and Objects: Encapsulation
Abstract Data Type.
Programming Logic and Design Seventh Edition
COMPSCI 107 Computer Science Fundamentals
Objects as a programming concept
Classes and OOP.
MPCS – Advanced java Programming
Object Oriented Programming using Java - Class Instance Variables
Chapter 3: Using Methods, Classes, and Objects
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Classes and Objects 2nd Lecture
Object Based Programming
Classes and Objects Encapsulation
Introduction to Data Structures
IFS410: Advanced Analysis and Design
Week 4 Object-based Programming (2) Classes and Objects: A Deeper Look
Data Structures and Algorithms for Information Processing
CS100J Lecture 7 Previous Lecture This Lecture Java Constructs
Introduction to Data Structure
CS360 Client/Server Programming Using Java
Chapter 8 Classes and Objects: A Deeper Look
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Review for Midterm 3.
Presentation transcript:

XuanTung Hoang 1 Something to discuss Feedbacks on Midterm Exam Final exam and term project  Final exam requires solid knowledge/skills in Java  Be more serious for the class! Understand lecture AT CLASS Practice at home (do homework) and at lab sessions. Self study for term project  Term project teams  Project topics Game Algorithm animation  Project proposal Next Week !

Programming Fundamentals I Java Programming Spring 2007 XuanTung Hoang Lecture No. 10

Encapsulation 1. Overview 2. Encapsulation 3. Information Hiding 4. Composition 5. Singleton

XuanTung Hoang 4 What’s next after midterm … ? We have learned almost every basics of Java  We can write java programs solve almost every computing problem. We will learn HOW TO ORGANIZE your program in a clever way.  For understanding  For reusability

XuanTung Hoang 5 Specifically, what will we learn? Writing Java program …  Creating class: Rules Tricks And patterns  If you follow (or use) those rules/tricks/patterns: You will write very good Java code!!! You will be able to USE classes provided by others effectively  Using class: Java Collection Framework Java I/O Java GUI Java Multithreading ….

XuanTung Hoang 6 Rule 1: Encapsulation Group related information into a class  Use instance variables  Provide related actions to process those variables Group related information together

XuanTung Hoang 7 Rule 1.1: Information Hiding Instance variable should be private Standardizing:  the way to change instance variables (with set methods)  the way to represent instance variables with get methods with predicate methods Expose necessary methods with public modifier 1.Don’t allow instance variables to be changed arbitrarily 2.Only expose necessary methods

XuanTung Hoang 8 Trick 1.2: Composition Bottom up design ! Example:  Define six classes Input, Output, Memory, CPU, ALU, Storage  Make Computer class that contains the above 6 classes You can combine classes to define another class

XuanTung Hoang 9 Case Study: Time Class (1) Validate parameter values before setting instance variables format strings, check JavaAPI manual for details private instance variables

XuanTung Hoang 10 Case Study: Time Class (2) Create a Time1 object Call setTime method Call setTime method with invalid values Call toString method Call toUniversalString method

XuanTung Hoang 11 Notes from the Case Study … hour, minute, second are private. They cannot be accessed/modified from other classes  Access/modify via set and get methods (e.g. setTime method)

XuanTung Hoang 12 Making hour, minute, second public is allowed, but it isn ’ t a good idea …  Hour, minute, second should store valid values. If they can be set freely, their values are very likely invalid. If hour, minute, second are private with appropriate set metho ds we can make sure that their values are always valid  appropriate set methods: Integrate validity checking in set method Other classes (clients) just call the set method without worries about invalidity. Complex detailed implementation related to private fields are hidden (information hiding)?

XuanTung Hoang 13 set, get, and predicate methods Data/information hiding is a property of class instance Typical classes has set, get, and predicate methods  set methods (mutators): validate and set the new values to instance  variables  get methods (accessors): obtain values of instance variables and control the format of the returned values E.g.: toUniversalString() can be considered as an get method  Predicate methods: test whether a certain condition on the object is true or false E.g.: we can add to class Time1 method is21Century() that tests whether the date is in the 21 st century or not. Great feature of OOP

XuanTung Hoang 14 Data abstraction and ADTs (1) Thanks to information hiding, clients care only what functionalities a class offers and don’t concern with how those functionalities are implemented. This concept is called data abstraction Data is not just the information like in common sense, data is the information and operations that can be performed on the information  Abstract Data Types (ADTs) ADTs = Data representation + Operations  In ADTs, data representation can be hidden

XuanTung Hoang 15 Data abstraction and ADTs (2) ADT Is a term that can refer to any type in current programming languages Java:  ADTs can be primitive types. E.g.: int (data representa-tion is int eger number; operations are arithmetic operations)  ADTs can be classes. E.g. Time1 class, Employee class Read section 8.15, text book

XuanTung Hoang 16 Pattern 1.3: Singleton In an application, if you have ONLY ONE instance of a class, use Singleton pattern. Singleton = Universal public Instance

XuanTung Hoang 17 Singleton pattern In a singleton class:  1 private static instance variable of singleton class (sInstance) Initialize it to null  1 public static method to: create object of Singleton class ONLY ONE  Guarantee ONLY ONE object creation by checking sInstance and return the singleton instance

XuanTung Hoang 18 Singleton Pattern

XuanTung Hoang 19 Examples of Singleton Universal Random number generator Universal Sequence number generator In CardGame project