1
17-214
Principles of Software Construction: Objects, Design, and - - PowerPoint PPT Presentation
Principles of Software Construction: Objects, Design, and Concurrency API Design, Part I: Process and Naming Charlie Garrod Chris Timperley 17-214 1 Administrivia Homework 4c due next Thursday Reading assignment due next Tuesday
1
17-214
2
17-214
– Effective Java, Items 6, 7, and 63
3
17-214
public MyWidget extends JContainer { ublic MyWidget(int param) {/ setup internals, without rendering } / render component on first view and resizing protected void paintComponent(Graphics g) { // draw a red box on his componentDimension d = getSize(); g.setColor(Color.red); g.drawRect(0, 0, d.getWidth(), d.getHeight());} } public MyWidget extends JContainer { ublic MyWidget(int param) {/ setup internals, without rendering } / render component on first view and resizing protected void paintComponent(Graphics g) { // draw a red box on his componentDimension d = getSize(); g.setColor(Color.red); g.drawRect(0, 0, d.getWidth(), d.getHeight());} }
your code your code
4
17-214
5
17-214
public class Change { public static void main(String args[]) { System.out.println(2.00 - 1.10); } }
6
17-214
public class Change { public static void main(String args[]) { System.out.println(2.00 - 1.10); } }
7
17-214
8
17-214
public class Change { public static void main(String args[]) { System.out.println(2.00 - 1.10); } }
9
17-214
// You could fix it this way... import java.math.BigDecimal; public class Change { public static void main(String args[]) { System.out.println( new BigDecimal("2.00").subtract( new BigDecimal("1.10"))); } } // ...or you could fix it this way public class Change { public static void main(String args[]) { System.out.println(200 - 110); } }
10
17-214
11
17-214
import java.math.BigDecimal; public class Change { public static void main(String args[]) { BigDecimal payment = new BigDecimal(2.00); BigDecimal cost = new BigDecimal(1.10); System.out.println(payment.subtract(cost)); } }
12
17-214
import java.math.BigDecimal; public class Change { public static void main(String args[]) { BigDecimal payment = new BigDecimal(2.00); BigDecimal cost = new BigDecimal(1.10); System.out.println(payment.subtract(cost)); } }
13
17-214
14
17-214
import java.math.BigDecimal; public class Change { public static void main(String args[]) { BigDecimal payment = new BigDecimal(2.00); BigDecimal cost = new BigDecimal(1.10); System.out.println(payment.subtract(cost)); } }
15
17-214
import java.math.BigDecimal; public class Change { public static void main(String args[]) { BigDecimal payment = new BigDecimal("2.00"); BigDecimal cost = new BigDecimal("1.10"); System.out.println(payment.subtract(cost)); } }
16
17-214
– Uses canonical string representation to construct decimal
17
17-214
Service* implementation
Hidden from service* provider Hidden from service* client
* service = object, subsystem, …
18
17-214
19
17-214
20
17-214
http://www.throughlinegroup.com/wp-content/uploads/2013/10/Paper-Buried-By.jpg
21
17-214
Your code Your colleague Another colleague ...
22
17-214
Eclipse (IBM) JDT Plugin (IBM) CDT Plugin (IBM) ...
23
17-214
24
17-214
25
17-214
26
17-214
27
17-214
28
17-214
29
17-214
30
17-214
31
17-214
– Better solutions may exist
– Should take the form of use-cases
32
17-214
33
17-214
34
17-214
// A collection of elements (root of the collection hierarchy) public interface Collection<E> { // Ensures that collection contains o boolean add(E o); // Removes an instance of o from collection, if present boolean remove(Object o); // Returns true iff collection contains o boolean contains(Object o) ; // Returns number of elements in collection int size() ; // Returns true if collection is empty boolean isEmpty(); ... // Remainder omitted }
35
17-214
36
17-214
37
17-214
38
17-214
39
17-214
https://docs.oracle.com/javase/8/docs/technotes/guides/collections/designfaq.html
40
17-214
41
17-214
42
17-214
43
17-214
44
17-214
45
17-214
46
17-214
47
17-214
48
17-214
49
17-214
50
17-214
51
17-214
52
17-214
53
17-214
54
17-214
55
17-214
56
17-214
57
17-214
58
17-214
59
17-214
60
17-214
61
17-214
62
17-214
63
17-214
64
17-214