Prog3 - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Prog3

Description:

Data and its operations bundled together. Data Hiding ... public void run() throws IOException. private void add(String dstr) private void sum(String dstr) ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 9
Provided by: qya
Category:

less

Transcript and Presenter's Notes

Title: Prog3


1
Prog3
2
Good OO Programming
  • ADT
  • Data and operations on that data
  • Data Encapsulation
  • Data and its operations bundled together
  • Data Hiding
  • Hiding the details of the implementation from
    the user

3
FixedPoint Class
  • Data
  • private int value, qVal
  • Constructors
  • public FixedPoint(double x, int q)
  • public FixedPoint( FixedPoint x )
  • private FixedPoint( int v, int q )
  • Operations
  • public String toString()
  • public boolean equals ( Object x )
  • public double toDouble()
  • public FixedPoint plus ( FixedPoint p, int
    resultQ )
  • public FixedPoint times ( FixedPoint p, int
    resultQ )
  • private FixedPoint changeQ ( int newQ )

4
  • private FixedPoint( int v, int q )
  • public FixedPoint( FixedPoint p )
  • private FixedPoint changeQ ( int newQ )
  • int qDiff newQ - qVal
  • if( qDiff gt 0 )
  • return new FixedPoint( value ltlt qDiff,
    newQ )
  • else if( qDiff lt 0 )
  • return new FixedPoint( value gtgt -qDiff,
    newQ )
  • else
  • return new FixedPoint( value, qVal )
  • //return new FixedPoint( this )

5
  • public class FixedPoint
  • private int value, qVal
  • ...
  • private FixedPoint changeQ ( int newQ )
  • ...
  • _at_Override
  • public boolean equals (Object p)
  • if ( p instanceof FixedPoint )
    FixedPoint x (FixedPoint)p return (
    value x.changeQ(qVal).value
  • this.changeQ(x.qVal).value
    x.value ) return false

6
  • public class FixedPoint
  • private int value, qVal
  • ...
  • private FixedPoint( int v, int q )
  • private FixedPoint changeQ ( int newQ )
  • ...
  • public FixedPoint plus ( FixedPoint p, int
    resultQ )
  • FixedPoint p1 changeQ(resultQ)
  • FixedPoint p2 p.changeQ(resultQ)
  • return new FixedPoint( p1.value p2.value,
    resultQ )

7
  • public class FixedPoint
  • private int value, qVal
  • ...
  • private FixedPoint( int v, int q )
  • private FixedPoint changeQ ( int newQ )
  • ...
  • public FixedPoint plus ( FixedPoint p, int
    resultQ )
  • return new FixedPoint(changeQ(resultQ).value
  • p.changeQ(resultQ).val
    ue,
  • resultQ )

8
Style
  • Class comment
  • Method (including constructor) comment
  • Comment style
  • Indentation
  • Tabs
  • Line too long
Write a Comment
User Comments (0)
About PowerShow.com