Programmer-Defined Types Object Types as Programmer-defined Types Two-way Dependencies Representation Errors Primitive Vs Object Properties Constructors.

Slides:



Advertisements
Similar presentations
Basic -2 Classes and Objects. Classes and Objects A class is a complex data TYPE An object is an instance of a class. Example: Class: Person Objects:
Advertisements

Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
Chapter 7: User-Defined Functions II
C OMP 401 C LASS S TATE Instructor: Prasun Dewan.
C OMP 110 S TYLE Instructor: Jason Carter. 2 I NTERFACES AND M ORE S TYLE Define contracts between our users and implementers Optional – they may not.
C OMP 110 L OAN C ASE S TUDY Instructor: Jason Carter.
Road Map Introduction to object oriented programming. Classes
By - Qiong Han. DON’T FALL BEHIND IN READING Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets.
Midterm Exam 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 1-5 (except char) PDF/PS with index and corrections coming.
Program Style Identifier Names Comments Named Constants Avoiding Code Repetition Giving Least Privilege Efficiency Interfaces.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Comp 14 (3) By Stephan Sherman Office hours, W, 3:00-3:50pm.
Class Variables & Methods More on dependencies Representation and representation errors Primitive vs. Object Properties Class Variables/Methods Primitive.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Main and Control Flow Programming without ObjectEditor Main Class Control Flow “Real” Programming Linear Branching Looping Programmer-Defined Overloading.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Object Types Primitive types Primitive Vs Object Types Types Classes ABMISpreadsheet AnotherBMISpreadsheet Interfaces BMISpreadsheet Loan Stringdoubleint.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
ObjectEditor Prasun Dewan Comp 114. ObjectEditor Automatic user-interface generation. You only write computation code Separate object to do I/O Main just.
Class Variables & Methods More on dependencies Representation and representation errors Primitive vs. Object Properties Class Variables/Methods Primitive.
State Instance Variables Procedures Properties Print Statements Println Vs Print Overloading J++
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Bicycle Car Types pedal() pushAccelerator(). Stringdoubleint Programming Language Types “three”“four” = 7 = “threefour” + + / = 0 / = 0.75.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
C OMP 401 C LASS S TATE Instructor: Prasun Dewan.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
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.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
C OMP 401: C ONSTRUCTORS AND P OINTERS Instructor: Prasun Dewan (FB 150,
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
ECE122 Feb. 22, Any question on Vehicle sample code?
C OMP 110/401 E NCAPSULATION AND L EAST P RIVILEGE Instructor: Prasun Dewan.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
CIS162AD Constructors Part 2 08_constructors.ppt.
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Topics Instance variables, set and get methods Encapsulation
C OMP 110/401 D OCUMENTATION : A NNOTATIONS Instructor: Prasun Dewan.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Chapter 2 Objects and Classes
Java Primer 1: Types, Classes and Operators
Chapter 3: Using Methods, Classes, and Objects
Instructor: Prasun Dewan
Classes & Objects: Examples
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Interfaces.
Recitation 4 September 16, 2011.
Classes and Objects.
Recitation 3 September 9, 2011 Wade Gobel.
Chapter 11 Inheritance and Encapsulation and Polymorphism
Chapter 7 Objects and Classes
SPL – PS3 C++ Classes.
Presentation transcript:

Programmer-Defined Types Object Types as Programmer-defined Types Two-way Dependencies Representation Errors Primitive Vs Object Properties Constructors Class variables/methods Top-Down, Bottom-up, Middle-out Programming

Loan Object

Properties Classification public class ABMISpreadsheet { double height; public double getHeight() { return height; } public void setHeight(double newHeight) { height = newHeight; } double weight; public double getWeight() { return weight; } public void setWeight(double newWeight) { weight = newWeight; } public double getBMI() { return weight/(height*height); } Height Weight BMI Editable Read-only Independent Dependent Read-Only

Read-Only Vs Editable, Dependent Vs Independent Editable Dependent

1-Way Vs. 2-Way Dependencies BMI Height Weight Principle Monthly Interest Yearly Interest

Top-Down Programming Interface Representation Algorithm Class

Bottom-up Programming in BMI Interface Class

Loan Object

Loan Interface public interface Loan { public int getPrincipal(); public void setPrincipal(int newValue); public int getYearlyInterest(); public void setYearlyInterest(int newVal); public int getMonthlyInterest(); public void setMonthlyInterest(int newVal); }

A Loan Representation setYearly Interest() setMonthly Interest() getYearly interest() setPrincipal()getPrincipal() getMonthly Interest() write read double principal

Stored Vs Computed Editable Dependent Stored Computed

Loan Algorithm setYearly Interest() setMonthly Interest() getYearly interest() setPrincipal()getPrincipal() getMonthly Interest() write read F1 -1 F2 -1 F1 F2 int principal

Setting and Getting Stored Property setPrincipal()getPrincipal() public void setPrincipal(int newVal) { principal = newVal; } public int getPrincipal(){ return principal; } int principal

Setting and Getting Stored Property setPrincipal()getPrincipal() public void setPrincipal(int newVal) { principal = newVal; } public int getPrincipal(){ return principal; } int principal

Getting and Setting Computed Property (edit) setYearly Interest() getYearly interest() write read F1 -1 F1 public int getYearlyInterest() { return principal* INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { ???? } int principal

Getting and Setting Computed Property (edited) setYearly Interest() getYearly interest() write read F1 -1 F1 public int getYearlyInterest() { return principal* INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { principal = newVal/INTEREST_RATE*100; } int principal

Getting and Setting Computed Property(soln) setYearly Interest() getYearly interest() write read F1 -1 F1 public int getYearlyInterest() { return principal* INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { principal = newVal*100/INTEREST_RATE; } int principal

Getting and Setting Computed Property (edit) setMonthly Interest() getMonthly Interest() F2 -1 F2 public int getMonthlyInterest() { ??? } public void setMonthlyInterest(int newVal) { ??? } int principal

Getting and Setting Computed Property (edited) setMonthly Interest() getMonthly Interest() F2 -1 F2 public int getMonthlyInterest() { return getYearlyInterest()/12; } public void setMonthlyInterest(int newVal) { setYearlyInterest (newVal*12); } int principal

Getting and Setting Computed Property(soln) setMonthly Interest() getMonthly Interest() F2 -1 F2 public int getMonthlyInterest() { return getYearlyInterest()/12; } public void setMonthlyInterest(int newVal) { principal = setYearlyInterest(newVal*12); } int principal

Modified Loan Interface public interface Loan { public final int INTEREST_RATE = 6; public int getPrincipal(); public void setPrincipal(int newValue); public int getYearlyInterest(); public void setYearlyInterest(int newVal); public int getMonthlyInterest(); public void setMonthlyInterest(int newVal); }

Middle-Out Programming Interface Representation Algorithm Class

Another Loan Representation int yearlyInterest setYearly Interest() setMonthly Interest() getYearly interest() setPrincipal()getPrincipal() getMonthly Interest() write read

Conversion Errors with Principal Repn.

No Conversion Errors with YearlyInterest Repn.

Car Loan House Loan Total Loan Principal Yearly Interest Monthly Interest Loan Pair Car Loan Yearly Interest Car Loan Monthly Interest House Loan Principal Car Loan Principal...

Primitive Vs. Object Properties Loan Pair Car Loan Principal Car Loan Yearly Interest Car Loan Monthly Interest House Loan Principal... Loan Pair Car Loan House Loan Total Loan Primitive Properties Object Properties Reusing Loan!

Loan Pair Interface (edit) public interface LoanPair {... }

Loan Pair Interface (edited) public interface LoanPair {... }

Loan AnotherLoan ALoan Typing Objects

Object Types Primitive types Kinds of Types Types Classes ABMISpreadsheet AnotherBMISpreadsheet Interfaces BMISpreadsheet Loan Stringdoubleint Type = Set of operations ALoan AnotherLoan

Loan Pair Interface (soln) public interface LoanPair { public Loan getCarLoan(); public void setCarLoan(Loan newValue); public Loan getHouseLoan(); public void setHouseLoan(Loan newValue); public Loan getTotalLoan(); } AnotherLoan Instance ALoan Instance Actual Parameters

Loan Pair Interface: Restricted public interface LoanPair { public Loan getCarLoan(); public void setCarLoan(ALoan newValue); public Loan getHouseLoan(); public void setHouseLoan(ALoan newValue); public Loan getTotalLoan(); } ALoan Instance AnotherLoan Instance Actual Parameters

Typing an Object Use interface rather than class to type object variables. => Define interfaces for all classes that include headers of all public method

Programmer-defined Vs Predefined Types Programmer-defined interface/class (Loan/ALoan) is programmer-defined type. Programmer-defined types in Java must be object types Some object types are predefined (String) All primitive types are predefined.

Space Efficient Representation Dependent Stored Computed Car Loan House Loan Total Loan Principal Yearly Interest Monthly Interest Dependent Independent

Space Efficient Representation Loan carLoan setHouseLoan() getHouseLoan() setCarLoan() getCarLoan() writeread Loan houseLoan getTotalLoan()

Getter Method Loan carLoan getCarLoan() public Loan getCarLoan(){ return carLoan; } Accessing Uninitialized Object Variable !!

variablesmemory Object Variables Primitive Variables Default Values for Variables height 0.0 weight null carLoan houseLoan Loan carLoan double height double weight Legal double Values Illegal Loan values

Invoking methods on null carLoan.getPrincipal() null pointer exception Exception is an unexpected event (error) Guilty method will be terminated and exception reported. Will see other exceptions later.

Getter Method Loan carLoan getCarLoan() public Loan getCarLoan(){ return carLoan; } ObjectEditor does not try to invoke methods if return value is null

ObjectEditor Display of Null

How to initialize object variable? Loan carLoan getCarLoan() public Loan getCarLoan(){ return carLoan; } Create instance (of ALoan or AnotherLoan) and assign to variable.

Initialization of Object Variables Loan carLoan = new ALoan() Loan houseLoan = new AnotherLoan() Loan houseLoan = new Loan()

Interactive Vs Programmed Instantiation new ALoan()

Programmed Instantiation new C(...) creates an instance of class C … is actual parameters. C is method and class name. cannot instantiate interface –new Loan() is illegal must order from a factory cannot order car from specification

ALoanPair Loan carLoan = new ALoan() setCarLoan() getCarLoan() writeread Loan houseLoan = new AnotherLoan() getTotalLoan() setHouseLoan() getHouseLoan()

getTotalLoan() Loan carLoan = new ALoan() Loan houseLoan = new AnotherLoan() getTotalLoan() public Loan getTotalLoan(){ houseLoan + carLoan; }

Programmer-Defined Add Algorithm public Loan add(Loan loan1, Loan loan2) { // create Loan instance // set one of its properties to sum of corresponding properties of loan 1 and loan2 // other properties are dependent and will be set automatically // return Loan instance }

Programmer-Defined Add public Loan add(Loan loan1, Loan loan2) { Loan retVal = new ALoan(); retVal.setPrincipal(loan1.getPrincipal() + loan2.getPrincipal()); return retVal; } public Loan add(Loan loan1, Loan loan2) { Loan retVal = new ALoan(); retVal.setYearlyInterest(loan1.getYearlyInterest() + loan2.getYearlyInterest()); return retVal; } public Loan add(Loan loan1, Loan loan2) { Loan retVal = new ALoan(); retVal.setMonthlyInterest(loan1.getMonthlyInterest() + loan2.getMonthlyInterest()); return retVal; }

public Loan add(Loan loan1, Loan loan2) { Loan retVal = new AnotherLoan(); retVal.setPrincipal(loan1.getPrincipal() + loan2.getPrincipal()); return retVal; } Returning AnotherLoan() public Loan add(Loan loan1, Loan loan2) { Loan retVal = new AnotherLoan(); retVal.setYearlyInterest(loan1.getYearlyInterest() + loan2.getYearlyInterest()); return retVal; } public Loan add(Loan loan1, Loan loan2) { Loan retVal = new AnotherLoan(); retVal.setMonthlyInterest(loan1.getMonthlyInterest() + loan2.getMonthlyInterest()); return retVal; }

Combining Object Creation and Initialization public Loan add(Loan loan1, Loan loan2) { Loan retVal = new ALoan(); retVal.setPrincipal(loan1.getPrincipal() + loan2.getPrincipal()); return retVal; } public Loan add(Loan loan1, Loan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } Object creation Object initialization Combined object creation and initialization

Adding Constructor in ALoan setYearly Interest() setMonthly Interest() getYearly interest() setPrincipal()getPrincipal() getMonthly Interest() write read int principal ALoan() initialize Constructor

Constructor Vs Regular Method public class ALoan implements Loan{ int principal; public int getPrincipal() { return principal; } public void setPrincipal(int newVal) { principal = newVal; } public int getYearlyInterest() { return principal*INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { principal = newVal*100/INTEREST_RATE; } public int getMonthlyInterest() { return getYearlyInterest()/12; } public void setMonthlyInterest(int newVal) { setYearlyInterest(newVal*12); } public ALoan(int initPrincipal) { setPrincipal(initPrincipal); } Combined type and method name Missing type name public ALoan ALoan(int initPrincipal) { setPrincipal(initPrincipal); } Not a constructor

Instantiation Requires Parameters new ALoan() new ALoan(10000)

Constructor Method that constructs a new object based on its parameters. –new ALoan(10000) Actually, just initializes object Object constructed by Java Front-end to object construction. Cannot be declared in interface Chooses implementation

Multi-Parameter Constructor public ALoanPair (Loan initCarLoan, Loan initHouseLoan) { setCarLoan(initCarLoan); setHouseLoan(initHouseLoan); } new ALoanPair(new ALoan(10000), new ALoan(10000)) Usually as many constructor parameters as are required to initialize independent instance variables.

Default Constructor public class ALoan implements Loan{ int principal; public int getPrincipal() { return principal; } public void setPrincipal(int newVal) { principal = newVal; } public int getYearlyInterest() { return principal*INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { principal = newVal*100/INTEREST_RATE; } public int getMonthlyInterest() { return getYearlyInterest()/12; } public void setMonthlyInterest(int newVal) { setYearlyInterest(newVal*12); } public ALoan() { } Inserted In Object Code not in Source Code Default new ALoan() Invoking Default, Parameterless Constructor

Real-World Analogy new AnAccord(beige) new AnAccord(grey) getMileage() blend(beigeCar, greyCar)numCarsProduced()

O-O Word new ALoan(10000) new ALoan(100000) getPrincipal() ALoan carLoan houseLoan add(carLoan, totalLoan) totalLoan numInstances() 3

Class Methods Methods can be invoked on class itself. Called class or static methods Declared in class on which they are invoked. Keyword static in header. Accesses no instance variable. Header cannot appear in interface.

Programmer-Defined Add public static Loan add(Loan loan1, Loan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } public Loan getTotalLoan(){ return ALoan.add (houseLoan, carLoan); } Accesses instance variables Instance Method Class Method Accesses no instance variable

External Call of Class Method ALoan.add(carLoan, houseLoan) Class as target Math.round(5.7)

numInstances() Algorithm Declare variable, numInstances initialized to zero Increment numInstances each time a new instance is created numInstances() returns numInstances

returning numLoans getNumLoans() returns numInstances public static int getNumLoans() { return numInstances; }

Incrementing getNumLoans (edit) Increment numInstances each time a new instance is created ???

Incrementing getNumLoans (edited) Increment numInstances each time a new instance is created ???

Incrementing getNumLoans (soln) Increment numInstances each time a new instance is created public ALoan(int initPrincipal) { setPrincipal(initPrincipal); numInstances = numInstances + 1; }

Declaring numInstances Declare variable, numInstances initialized to zero int numInstances = 0; // instance variable

1 memory Loan Object int numInstances = 0; public ALoan(int initPrincipal) { setPrincipal(initPrincipal); numInstances = numInstances + 1; } 0 principal 0 numInstances 0 principal 0 numInstances

1 memory Loan Object static int numInstances = 0; public ALoan(int initPrincipal) { setPrincipal(initPrincipal); numInstances = numInstances + 1; } 0 numInstances 0 principal principal

Instance Vs Class Members Class Members –Class methods –Class variables Instance Members –Instance methods –Instance variables

Scope of Class and Instance Members Class Members –visible to other class members –visible to all instance members class & instance methods can access class variables class and instance methods can call class methods Instance Members –visible to other instance members –not visible to class members which of (zero to many) copies of an instance variable should a class member refer to?

public static int getNumLoans() { System.out.println(principal); return numInstances; } Legal & Illegal Accesses static int numInstances = 0; public ALoan(int initPrincipal) { setPrincipal(initPrincipal); numInstances = numInstances + 1; System.out.println(getNumLoans()); } int principal; public setPrincipal(int newPrincipal) { principal = newPrincipal; }

public class AnotherBMISpreadsheet implements BMISpreadsheet{ double height, weight, bmi;... public static final double LBS_IN_KG = 2.2; public static final double CMS_IN_INCH = 2.54; double calculateBMI() { return (weight/LBS_IN_KG) / (height*CMS_IN_INCH/100*height*CMS_IN_INCH/100); } Instance Vs Class Named Constant memory LBS_IN_KG 0 new AnotherBMISpreadsheet() AnotherBMISpreadsheet.LBS_IN_KG

public class AnotherBMISpreadsheet implements BMISpreadsheet{ double height, weight, bmi;... final double LBS_IN_KG = 2.2; final double CMS_IN_INCH = 2.54; double calculateBMI() { return (weight/LBS_IN_KG) / (height*CMS_IN_INCH/100*height*CMS_IN_INCH/100); } Instance Vs Class Named Constant memory LBS_IN_KG 0 new AnotherBMISpreadsheet() LBS_IN_KG 0 public final double LBS_IN_KG = 2.2; (new AnotherBMISpreadsheet()).LBS_IN_KG

Class Vs Instance Constant Should be class constant –one copy –easy to refer (require no instance creation) Unless some good reason for hiding named constants from static methods See inheritance-based exception later

Class Vs Instance Methods public static Loan add(Loan loan1, Loan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } Class MethodAccesses no instance variable public Loan add(Loan loan1, Loan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } Instance Method ALoan.add(carLoan, houseLoan) Math.round(5.7) (new ALoan).add(carLoan, houseLoan) (new Math).round(5.7)

Class Vs Instance Method Instance method has all the privileges of a class method. Any class method can be made an instance method. Bad style to have instance method that does not access any instance variable. –They belong to the class. –Violate least privilege principle. –Require needless instantiation.

Class Vs Instance Constant/Method Named constants should be static –Unless some good reason for hiding named constants from static methods –See inheritance-based exception later Methods not accessing instance variables should be static –Unless need to be listed in interface. –See inheritance-based exception later

Polymorphic Methods public static Loan add(Loan loan1, Loan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } AnotherLoan Instance ALoan Instance Actual Parameters of different types Methods that take actual parameters of different types

Non Polymorphic Methods public static Loan add(ALoan loan1, ALoan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } public static Loan add(AnotherLoan loan1, AnotherLoan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } public static Loan add(ALoan loan1, AnotherLoan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } Code Duplication

public static Loan add(ALoan loan1, ALoan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } Overloading Vs Polymprphism add (new ALoan(10000), new ALoan(5000)); add (new ALoan(10000), new AnotherLoan(5000)); PolymorphismOverloading public static Loan add(ALoan loan1, AnotherLoan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); } public static Loan add(ALoan loan1, ALoan loan2) { return new ALoan(loan1.getPrincipal() + loan2.getPrincipal())); }

Object Types Primitive types Primitive Vs Object Types Types Classes ABMISpreadsheet AnotherBMISpreadsheet Interfaces BMISpreadsheet Loan Stringdoubleint Type = Set of operations ALoan AnotherLoan

Structure Types Primitive types Structure Vs Atomic Types Types Classes ABMISpreadsheet AnotherBMISpreadsheet Interfaces BMISpreadsheet Loan Stringdoubleint ALoan AnotherLoan Instances of structure type decomposed into one or more smaller values

Loan Interface public interface Loan { public int getPrincipal(); public void setPrincipal(int newValue); public int getYearlyInterest(); public void setYearlyInterest(int newVal); public int getMonthlyInterest(); public void setMonthlyInterest(int newVal); }

A Loan Representation setYearly Interest() setMonthly Interest() getYearly interest() setPrincipal()getPrincipal() getMonthly Interest() write read double principal

Another Loan Representation int yearlyInterest setYearly Interest() setMonthly Interest() getYearly interest() setPrincipal()getPrincipal() getMonthly Interest() write read

Physical Vs. Logical Structure ALoan instance double principalALoan instance double Principal Yearly Interest Monthly Interest double Physical Logical

Loan Pair Interface public interface LoanPair { public Loan getCarLoan(); public void setCarLoan(Loan newValue); public Loan getHouseLoan(); public void setHouseLoan(Loan newValue); public Loan getTotalLoan(); }

ALoanPair Loan carLoan = new ALoan() setCarLoan() getCarLoan() writeread Loan houseLoan = new AnotherLoan() getTotalLoan() setHouseLoan() getHouseLoan()

Physical Vs. Logical Structure ALoan double principal Loan double Principal Yearly Interest Monthly Interest double Physical Logical ALoanPair Instance carLoan houseLoan yearlyInterest AnotherLoandouble ALoanPair Instance CarLoan Loan HouseLoan TotalLoan Loan Variable Name Class/primitive type of value Stored in Variable Property Name Property Type