Interfaces. consider an interface for mathematical functions of the form

Size: px
Start display at page:

Download "Interfaces. consider an interface for mathematical functions of the form"

Transcription

1 1 Interfaces

2 Interfaces in its most common form, a Java interface is a declaration (but not an implementation) of an API in its most common form, an interface is made up of public abstract methods an abstract method is a method that has an API but does not have an implementation consider an interface for mathematical functions of the form 2

3 import java.util.list; public interface Function { /** * Evaluate the function at x. * x the value at which to evaluate the function the value of the function evaluated at x */ public double eval(double x); semicolon, and no method body /** * Evaluate the function at each value of x in the given list. * x a list of values at which to evaluate the function the list of values of the function evaluated at the given * values of x */ public List<Double> eval(list<double> x); semicolon, and no method body 3

4 Interfaces notice that the interface declares which methods exist and specifies the contract of the methods but it does not specify how the methods are implemented the method implementations are defined by classes that implement the interface consider the functions:,, 4

5 public class Square implements Function public double eval(double x) { return x * x; Square implements the Function interface Square must provide an implementation of public List<Double> eval(list<double> x) { List<Double> result = new ArrayList<>(); for (Double val : x) { result.add(this.eval(val)); return result; Square must provide an implementation of eval(list<double>) // no constructors because Square has no fields 5

6 public class Reciprocal implements Function { Reciprocal implements the Function public double eval(double x) { return 1.0 / x; Reciprocal must provide an implementation of public List<Double> eval(list<double> x) { List<Double> result = new ArrayList<>(); for (Double val : x) { result.add(this.eval(val)); return result; Reciprocal must provide an implementation of eval(list<double>) // no constructors because Reciprocal has no fields 6

7 public class SquareWave implements Function { SquareWave implements the Function interface private int nmax; public SquareWave(int nmax) { SquareWave must provide an if (nmax < 1) { implementation of eval(double) throw new IllegalArgumentException(); this.nmax = public double eval(double x) { double result = 0; for (int n = 1; n < this.nmax; n += 2) { result += Math.sin(n * Math.PI * x) / n; return 4 / Math.PI * result; 7

8 @Override public List<Double> eval(list<double> x) { List<Double> result = new ArrayList<>(); for (Double val : x) { result.add(this.eval(val)); return result; SquareWave must provide an implementation of eval(list<double>) 8

9 SquareWave SquareWave implements the Fourier series for a square wave results for nmax = 101 9

10 Interfaces in the Java library interfaces are widely used in the Java library Collection, List, Set, Map Iterable, Iterator CharSequence, Appendable Comparable 10

11 Interfaces are types an interface is a reference data type if you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface ( List<String> t = new ArrayList<String>(); interface implements the interface 11

12 Interfaces are types an interface is a reference data type if you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface ( Function f = new SquareWave(101); interface implements the interface 12

13 Inheritance Notes Chapter 6 13

14 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? 14

15 Object Dog is-a Object Dog PureBreed is-a Dog PureBreed is-a Object PureBreed Mix BloodHound Komondor... Komondor is-a PureBreed Komondor is-a Dog Komondor is-a Object 15

16 superclass of Dog (and all other classes) subclass of Object superclass of PureBreed Object Dog superclass == base class parent class subclass == derived class extended class child class subclass of Dog superclass of Komondor PureBreed Mix BloodHound Komondor... 16

17 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 17

18 Some Definitions we say that a subclass is derived from its superclass with the exception of Object, every class in Java has one and only one superclass Java only supports single inheritance a class X can be derived from a class that is derived from a class, and so on, all the way back to Object X is said to be descended from all of the classes in the inheritance chain going back to Object all of the classes X is derived from are called ancestors of X 18

19 Why Inheritance? a subclass inherits all of the non private members (fields and methods but not constructors) from its superclass if there is an existing class that provides some of the functionality you need you can derive a new class from the existing class the new class has direct access to the public and protected attributes and methods without having to redeclare or re implement them the new class can introduce new fields and methods the new class can re define (override) its superclass methods 19

20 Is A inheritance models the is a relationship between classes is a means is substitutable for 20

21 Is A from a Java point of view, is a means you can use a derived class instance in place of an ancestor class instance public SomeClass { public somemethod(dog dog) { // does something with dog 21 // client code of somemethod Komondor shaggy = new Komondor(); SomeClass.someMethod( shaggy ); // OK, Komondor is-a dog Mix mutt = new Mix (); SomeClass.someMethod( mutt ); // OK, Mix is-a dog

22 Is A Pitfalls is a has nothing to do with the real world is a has everything to do with how the implementer has modelled the inheritance hierarchy the classic example: Circle is a Ellipse? Ellipse Circle 22

23 Circle is a Ellipse? mathematically a circle is a kind of ellipse but if Ellipse can do something that Circle cannot, then Circle is a Ellipse is false for the purposes of inheritance remember: is a means you can substitute a derived class instance for one of its ancestor instances if Circle cannot do something that Ellipse can do then you cannot (safely) substitute a Circle instance for an Ellipse instance 23

24 // method in Ellipse /* * Change the width and height of the ellipse. width the desired width. height the desired height. width > 0 && height > 0 */ public void setsize(double width, double height) { this.width = width; this.height = height; 24

25 there is no good way for Circle to support setsize (assuming that the fields width and height are always the same for a Circle) because clients expect setsize to set both the width and height can't Circle override setsize so that it throws an exception if width!= height? no; this will surprise clients because Ellipse.setSize does not throw an exception if width!= height can't Circle override setsize so that it sets width == height? no; this will surprise clients because Ellipse.setSize says that the width and height can be different 25

26 what if there is no setsize method? if a Circle can do everything an Ellipse can do then Circle can extend Ellipse 26

27 A Naïve Inheritance Example a stack is an important data structure in computer science data structure: an organization of information for better algorithm efficiency or conceptual unity e.g., list, set, map, array widely used in computer science and computer engineering e.g., undo/redo can be implemented using two stacks 27

28 Stack examples of stacks 28

29 Top of Stack top of the stack 29

30 Stack Operations classically, stacks only support two operations 1. push 2. pop add to the top of the stack remove from the top of the stack there is no way to access elements of the stack except at the top of the stack 30

31 Push 1. st.push("a") 2. st.push("b") 3. st.push("c") 4. st.push("d") 5. st.push("e") top top top top top "E" "D" "C" "B" "A" 31

32 Pop 1. String s = st.pop() 2. s = st.pop() 3. s = st.pop() 4. s = st.pop() 5. s = st.pop() top top top top top "E" "D" "C" "B" "A" 32

33 Implementing stack using inheritance a stack looks a lot like a list pushing an element onto the top of the stack looks like adding an element to the end of a list popping an element from the top of a stack looks like removing an element from the end of the list if we have stack inherit from list, our stack class inherits the add and remove methods from list we don't have to implement them ourselves let's try making a stack of integers by inheriting from ArrayList<Integer> 33

34 Implementing stack using inheritance import java.util.arraylist; public class BadStack extends ArrayList<Integer> { use the keyword extends followed by the name of the class that you want to extend 34

35 Implementing stack using inheritance import java.util.arraylist; public class BadStack extends ArrayList<Integer> { public void push(int value) { this.add(value); push = add to end of this list public int pop() { pop = remove from end of this list int last = this.remove(this.size() 1); return last; 35

36 Implementing stack using inheritance that's it, we re done! public static void main(string[] args) { BadStack t = new BadStack(); t.push(0); t.push(1); t.push(2); System.out.println(t); System.out.println("pop: " + t.pop()); System.out.println("pop: " + t.pop()); System.out.println("pop: " + t.pop()); [0, 1, 2] pop: 2 pop: 1 pop: 0 36

37 Implementing stack using inheritance why is this a poor implementation? by having BadStack inherit from ArrayList<Integer> we are saying that a stack is a list anything a list can do, a stack can also do, such as: get a element from the middle of the stack (instead of only from the top of the stack) set an element in the middle of the stack iterate over the elements of the stack 37

38 Implementing stack using inheritance public static void main(string[] args) { BadStack t = new BadStack(); t.push(100); t.push(200); t.push(300); System.out.println("get(1)?: " + t.get(1)); t.set(1, 1000); System.out.println("set(1, 1000)?: " + t); [100, 200, 300] get(1)?: 200 set(1, 1000)?: [100, 1000, 300] 38

39 Implementing stack using inheritance using inheritance to implement a stack is an example of an incorrect usage of inheritance inheritance should only be used when an is a relationship exists a stack is not a list, therefore, we should not use inheritance to implement a stack even experts sometimes get this wrong early versions of the Java class library provided a stack class that inherited from a list like class java.util.stack 39

40 Other ways to implement stack use composition Stack has a List the end of the list is the top of the stack push adds an element to the end of the list pop removes the element at the end of the list 40

41 Inheritance (Part 2) Notes Chapter 6 41

42 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 42

43 Implementing Inheritance suppose you want to implement an inheritance hierarchy that represents breeds of dogs for the purpose of helping people decide what kind of dog would be appropriate for them many possible fields: appearance, size, energy, grooming requirements, amount of exercise needed, protectiveness, compatibility with children, etc. we will assume two fields measured on a 10 point scale size from 1 (small) to 10 (giant) energy from 1 (lazy) to 10 (high energy) 43

44 Dog public class Dog extends Object { private int size; private int energy; // creates an "average" dog Dog() { this(5, 5); Dog(int size, int energy) { this.setsize(size); this.setenergy(energy); 44

45 public int getsize() { return this.size; public int getenergy() { return this.energy; public final void setsize(int size) { this.size = size; public final void setenergy(int energy) { this.energy = energy; why final? stay tuned 45

46 What is a Subclass? a subclass looks like a new class that has the same API as its superclass with perhaps some additional methods and fields the new class has direct access to the public and protected* fields and methods without having to redeclare or re implement them the new class can introduce new fields and methods the new class can re define (override) its superclass methods 46 * the notes does not discuss protected access

47 Mix UML Diagram a mixed breed dog is a dog whose ancestry is unknown or includes more than one pure breed Dog Mix 1 breeds ArrayList<String> 47

48 Dog - size : int - energy : int + setsize() + setenergy() + equals(object) : boolean + hashcode() : int + tostring() : String... Mix - breeds : ArrayList<String> + getbreeds() : List<String> + equals(object) : boolean + hashcode() : int + tostring() : String... subclass can add new fields subclass can add new methods subclass can change the implementation of inherited methods 48

49 What is a Subclass? a subclass looks like a new class that has the same API as its superclass with perhaps some additional methods and fields inheritance does more than copy the API of the superclass the derived class contains a subobject of the parent class the superclass subobject needs to be constructed (just like a regular object) the mechanism to perform the construction of the superclass subobject is to call the superclass constructor 49

50 What is a Subclass? another model of inheritance is to imagine that the subclass contains all of the fields of the parent class (including the private fields), but cannot directly use the private fields 50

51 Mix Memory Diagram size and energy belong to the superclass private in superclass not accessible by name to Mix 500 Mix object size 1 energy 10 breeds 1000a 51

52 Constructors of Subclasses the purpose of a constructor is to set the values of the fields of this object how can a constructor set the value of a field that belongs to the superclass and is private? by calling the superclass constructor and passing this as an implicit argument 52

53 Constructors of Subclasses 1. the first line in the body of every constructor must be a call to another constructor if it is not then Java will insert a call to the superclass default constructor if the superclass default constructor does not exist or is private then a compilation error occurs 2. a call to another constructor can only occur on the first line in the body of a constructor 3. the superclass constructor must be called during construction of the derived class 53

54 Mix (version 1) public final class Mix extends Dog { // no declaration of size or energy; part of Dog private ArrayList<String> breeds; public Mix () { // call to a Dog constructor super(); this.breeds = new ArrayList<String>(); public Mix(int size, int energy) { // call to a Dog constructor super(size, energy); this.breeds = new ArrayList<String>(); 54

55 public Mix(int size, int energy, ArrayList<String> breeds) { // call to a Dog constructor super(size, energy); this.breeds = new ArrayList<String>(breeds); 55

56 Mix (version 2 using chaining) public final class Mix extends Dog { // no declaration of size or energy; part of Dog private ArrayList<String> breeds; public Mix () { // call to a Mix constructor this(5, 5); public Mix(int size, int energy) { // call to a Mix constructor this(size, energy, new ArrayList<String>()); 56

57 public Mix(int size, int energy, ArrayList<String> breeds) { // call to a Dog constructor super(size, energy); this.breeds = new ArrayList<String>(breeds); 57

58 why is the constructor call to the superclass needed? because Mix is a Dog and the Dog part of Mix needs to be constructed 58

59 Mix mutt = new Mix(1, 10); Mix object Dog object 1. Mix constructor starts running creates new Dog subobject by invoking the Dog constructor 2. Dog constructor starts running creates new Object subobject by (silently) invoking the Object constructor 3. Object constructor runs and finishes sets size and energy and finishes creates a new empty ArrayList and assigns it to breeds and finishes Object object size 1 energy 10 breeds

60 Mix Memory Diagram 500 Mix object size 1 energy 10 breeds 1000a 1000 ArrayList<String> object... 60

61 Invoking the Superclass Ctor why is the constructor call to the superclass needed? because Mix is a Dog and the Dog part of Mix needs to be constructed similarly, the Object part of Dog needs to be constructed 61

62 Invoking the Superclass Ctor a derived class can only call its own constructors or the constructors of its immediate superclass Mix can call Mix constructors or Dog constructors Mix cannot call the Object constructor Object is not the immediate superclass of Mix Mix cannot call PureBreed constructors cannot call constructors across the inheritance hierarchy PureBreed cannot call Komondor constructors cannot call subclass constructors 62

63 Constructors & Overridable Methods if a class is intended to be extended then its constructor must not call an overridable method Java does not enforce this guideline why? recall that a derived class object has inside of it an object of the superclass the superclass object is always constructed first, then the subclass constructor completes construction of the subclass object the superclass constructor will call the overridden version of the method (the subclass version) even though the subclass object has not yet been constructed 63

64 Superclass Ctor & Overridable Method public class SuperDuper { public SuperDuper() { // call to an over-ridable method; bad this.overrideme(); public void overrideme() { System.out.println("SuperDuper overrideme"); 64

65 Subclass Overrides Method public class SubbyDubby extends SuperDuper { private final Date date; public SubbyDubby() { super(); this.date = new public void overrideme() { System.out.println("SubbyDubby overrideme : " + this.date); public static void main(string[] args) { SubbyDubby sub = new SubbyDubby(); sub.overrideme(); 65

66 the programmer's intent was probably to have the program print: SuperDuper overrideme SubbyDubby overrideme : <the date> or, if the call to the overridden method was intentional SubbyDubby overrideme : <the date> SubbyDubby overrideme : <the date> but the program prints: SubbyDubby overrideme : null SubbyDubby overrideme : <the date> final attribute in two different states! 66

67 What's Going On? 1. new SubbyDubby() calls the SubbyDubby constructor 2. the SubbyDubby constructor calls the SuperDuper constructor 3. the SuperDuper constructor calls the method overrideme which is overridden by SubbyDubby 4. the SubbyDubby version of overrideme prints the SubbyDubby date field which has not yet been assigned to by the SubbyDubby constructor (so date is null) 5. the SubbyDubby constructor assigns date 6. SubbyDubby overrideme is called by the client 67

68 remember to make sure that your base class constructors only call final methods or private methods if a base class constructor calls an overridden method, the method will run in an unconstructed derived class 68

69 Preconditions and Inheritance precondition what the method assumes to be true about the arguments passed to it inheritance (is a) a subclass is supposed to be able to do everything its superclasses can do how do they interact? 69

70 Preconditions and Inheritance a subclass can change a precondition on a method but whatever argument values the superclass method accepts must also be accepted by the subclass method 70

71 Strength of a Precondition to strengthen a precondition means to make the precondition more restrictive // Dog setenergy // 1. no precondition // 2. 1 <= energy // 3. 1 <= energy <= 10 // 4. energy == 5 public void setenergy(int energy) {... weakest precondition strongest precondition 71

72 Preconditions on Overridden Methods a subclass can change a precondition on a method but it must not strengthen the precondition a subclass that strengthens a precondition is saying that it cannot do everything its superclass can do // Dog setenergy // assume non-final none public void setenergy(int nrg) { //... // Mix setenergy // bad : strengthen precond. 1 <= nrg <= 10 public void setenergy(int nrg) { if (nrg < 1 nrg > 10) { // throws exception //... 72

73 client code written for Dogs now fails when given a Mix // client code that sets a Dog's energy to zero public void walk(dog d) { d.setenergy(0); remember: a subclass must be able to do everything its ancestor classes can do; otherwise, clients will be (unpleasantly) surprised 73

74 Postconditions and Inheritance postcondition what the method promises to be true when it returns the method might promise something about its return value "returns size where size is between 1 and 10 inclusive" the method might promise something about the state of the object used to call the method "sets the size of the dog to the specified size" the method might promise something about one of its parameters how do postconditions and inheritance interact? 74

75 Postconditions and Inheritance a subclass can change a postcondition on a method but whatever the superclass method promises will be true when it returns must also be true when the subclass method returns 75

76 Strength of a Postcondition to strengthen a postcondition means to make the postcondition more restrictive // Dog getsize // 1. no postcondition // 2. return value >= 1 // 3. return value // between 1 and 10 // 4. return 5 public int getsize() {... weakest postcondition strongest postcondition 76

77 Postconditions on Overridden Methods a subclass can change a postcondition on a method but it must not weaken the postcondition a subclass that weakens a postcondition is saying that it cannot do everything its superclass can do // Dog getsize // 1 <= size <= 10 public int getsize() { //... // Dogzilla getsize // bad : weaken postcond. 1 <= size public int getsize() { //... Dogzilla: a made up breed of dog that has no upper limit on its size 77

78 client code written for Dogs can now fail when given a Dogzilla // client code that assumes Dog size <= 10 public String sizetostring(dog d) { int sz = d.getsize(); String result = ""; if (sz < 4) result = "small"; else if (sz < 7) result = "medium"; else if (sz <= 10) result = "large"; return result; remember: a subclass must be able to do everything its ancestor classes can do; otherwise, clients will be (unpleasantly) surprised 78

79 Exceptions all exceptions are objects that are subclasses of java.lang.throwable Throwable Exception RuntimeException and many, many more IllegalArgumentException and many more 79 AJ chapter 9

80 User Defined Exceptions you can define your own exception hierarchy often, you will subclass Exception Exception DogException public class DogException extends Exception BadSizeException NoFoodException BadDogException 80

81 Exceptions and Inheritance a method that claims to throw a checked exception of type X is allowed to throw any checked exception type that is a subclass of X this makes sense because exceptions are objects and subclass objects are substitutable for ancestor classes // in Dog public void somedogmethod() throws DogException { // can throw a DogException, BadSizeException, // NoFoodException, or BadDogException 81

82 a method that overrides a superclass method that claims to throw a checked exception of type X can also claim to throw a checked exception of type X or a subclass of X remember: a subclass is substitutable for the parent type // in public void somedogmethod() throws DogException { //... 82

83 Inheritance (cont) Abstract Classes 83

84 Polymorphism inheritance allows you to define a base class that has fields and methods classes derived from the base class can use the public and protected base class fields and methods polymorphism allows the implementer to change the behaviour of the derived class methods 84

85 // client code public void print(dog d) { System.out.println( d.tostring() ); Dog tostring CockerSpaniel tostring Mix tostring // later on... Dog fido = new Dog(); CockerSpaniel lady = new CockerSpaniel(); Mix mutt = new Mix(); this.print(fido); this.print(lady); this.print(mutt); 85

86 notice that fido, lady, and mutt were declared as Dog, CockerSpaniel, and Mutt what if we change the declared type of fido, lady, and mutt? 86

87 // client code public void print(dog d) { System.out.println( d.tostring() ); Dog tostring CockerSpaniel tostring Mix tostring // later on... Dog fido = new Dog(); Dog lady = new CockerSpaniel(); Dog mutt = new Mix(); this.print(fido); this.print(lady); this.print(mutt); 87

88 what if we change the print method parameter type to Object? 88

89 // client code public void print(object obj) { System.out.println( obj.tostring() ); // later on... Dog fido = new Dog(); Dog lady = new CockerSpaniel(); Dog mutt = new Mix(); this.print(fido); this.print(lady); this.print(mutt); this.print(new Date()); Dog tostring CockerSpaniel tostring Mix tostring Date tostring 89

90 Late Binding polymorphism requires late binding of the method name to the method definition late binding means that the method definition is determined at run time non static method obj.tostring() run time type of the instance obj 90

91 Declared vs Run time type Dog lady = new CockerSpaniel(); declared type run time or actual type 91

92 the declared type of an instance determines what methods can be used Dog lady = new CockerSpaniel(); the name lady can only be used to call methods in Dog lady.somecockerspanielmethod() won't compile 92

93 Dynamic dispatch the actual type of the instance determines what definition is used when the method is called Dog lady = new CockerSpaniel(); lady.tostring() uses the CockerSpaniel definition of tostring selecting which version of a polymorphic method to use at run time is called dynamic dispatch 93

94 94 Abstract classes

95 Abstract Classes sometimes you will find that you want the API for a base class to have a method that the base class cannot define e.g. you might want to know what a Dog's bark sounds like but the sound of the bark depends on the breed of the dog you want to add the method bark to Dog but only the subclasses of Dog can implement bark 95

96 Abstract Classes sometimes you will find that you want the API for a base class to have a method that the base class cannot define e.g. you might want to know the breed of a Dog but only the subclasses have information about the breed you want to add the method getbreed to Dog but only the subclasses of Dog can implement getbreed 96

97 if the base class has methods that only subclasses can define and the base class has fields common to all subclasses then the base class should be abstract if you have a base class that just has methods that it cannot implement then you probably want an interface abstract : (dictionary definition) existing only in the mind in Java an abstract class is a class that you cannot make instances of e.g. 97

98 an abstract class provides a partial definition of a class the "partial definition" contains everything that is common to all of the subclasses the subclasses complete the definition an abstract class can define fields and methods subclasses inherit these an abstract class can define constructors subclasses must call these an abstract class can declare abstract methods 98 subclasses must define these (unless the subclass is also abstract)

99 Abstract Methods an abstract base class can declare, but not define, zero or more abstract methods public abstract class Dog { // fields, ctors, regular methods public abstract String getbreed(); the base class is saying "all Dogs can provide a String describing the breed, but only the subclasses know enough to implement the method" 99

100 Abstract Methods the non abstract subclasses must provide definitions for all abstract methods consider getbreed in Mix 100

101 public class Mix extends Dog { // stuff from public String getbreed() { if(this.breeds.isempty()) { return "mix of unknown breeds"; StringBuffer b = new StringBuffer(); b.append("mix of"); for(string breed : this.breeds) { b.append(" " + breed); return b.tostring(); 101

102 PureBreed a purebreed dog is a dog with a single breed one String field to store the breed note that the breed is determined by the subclasses the class PureBreed cannot give the breed field a value but it can implement the method getbreed the class PureBreed defines an field common to all subclasses and it needs the subclass to inform it of the actual breed PureBreed is also an abstract class 102

103 public abstract class PureBreed extends Dog { private String breed; public PureBreed(String breed) { super(); this.breed = breed; public PureBreed(String breed, int size, int energy) { super(size, energy); this.breed = breed; 103

104 @Override public String getbreed() { return this.breed; 104

105 Subclasses of PureBreed the subclasses of PureBreed are responsible for setting the breed consider Komondor 105

106 Komondor public class Komondor extends PureBreed { private final String BREED = "komondor"; public Komondor() { super(breed); public Komondor(int size, int energy) { super(breed, size, energy); // other Komondor methods

107 Another example: Tetris played with 7 standard blocks called tetriminoes blocks drop from the top player can move blocks left, right, and down player can spin blocks left and right 107

108 Tetriminoes spinning the I, J, and S blocks 108

109 Tetriminoes features common to all tetriminoes has a color has a shape has a position draw move left, right, and down features unique to each kind of tetrimino the actual shape spin left and right 109

110 Block - color : Color - position : Point2 - grid : BlockGrid # Block(int, Point2, Color) + draw() + movedown() + moveleft() + moveright()... class name in italics for abstract classes a2dpoint agrid object that stores the shape protected constructor Block is abstract because we can't define the shape of a generic block IBlock + IBlock(Point2, Color) + spinleft() + spinright() constructor defines the shape methods modify the shape to produce the rotated version of the block /F/2030/labs/lab4/lab4.html

111 Inheritance (cont) Static Features 111

112 Static Fields and Inheritance static fields behave the same as non static fields in inheritance public and protected static fields are inherited by subclasses, and subclasses can access them directly by name private static fields are not inherited and cannot be accessed directly by name but they can be accessed/modified using public and protected methods 112

113 Static Fields and Inheritance the important thing to remember about static fields and inheritance there is only one copy of the static field shared among the declaring class and all subclasses consider trying to count the number of Dog objects created by using a static counter 113

114 // the wrong way to count the number of Dogs created public abstract class Dog { // other fields... static protected int numcreated = 0; protected, not private, so that subclasses can modify it directly Dog() { //... Dog.numCreated++; public static int getnumbercreated() { return Dog.numCreated; // other contructors, methods

115 // the wrong way to count the number of Dogs created public class Mix extends Dog { // fields... Mix() { super(); Mix.numCreated++; // other contructors, methods

116 // too many dogs! public class TooManyDogs { public static void main(string[] args) { Mix mutt = new Mix(); System.out.println( Mix.getNumberCreated() ); prints 2 116

117 What Went Wrong? there is only one copy of the static field shared among the declaring class and all subclasses Dog declared the static field Dog increments the counter every time its constructor is called Mix inherits and shares the single copy of the field Mix constructor correctly calls the superclass constructor which causes numcreated to be incremented by Dog Mix constructor then incorrectly increments the counter 117

118 Counting Dogs and Mixes suppose you want to count the number of Dog instances and the number of Mix instances Mix must also declare a static field to hold the count somewhat confusingly, Mix can give the counter the same name as the counter declared by Dog 118

119 public class Mix extends Dog { // other fields... private static int numcreated = 0; // bad style; hides Dog.numCreated public Mix() { super(); // will increment Dog.numCreated // other Mix stuff... numcreated++; // will increment Mix.numCreated //

120 Hiding Fields note that the Mix field numcreated has the same name as an field declared in a superclass whenever numcreated is used in Mix, it is the Mix version of the field that is used if a subclass declares an field with the same name as a superclass field, we say that the subclass field hides the superclass field considered bad style because it can make code hard to read and understand should change numcreated to nummixcreated in Mix 120

121 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non static method when dealing with inheritance there is no dynamic dispatch on static methods therefore, you cannot override a static method 121

122 public abstract class Dog { private static int numcreated = 0; public static int getnumcreated() { return Dog.numCreated; public class Mix { private static int nummixcreated = 0; public static int getnumcreated() { return Mix.numMixCreated; notice public class Komondor { private static int numkomondorcreated = 0; public static int getnumcreated() { return Komondor.numKomondorCreated; notice 122

123 public class WrongCount { public static void main(string[] args) { Dog mutt = new Mix(); Dog shaggy = new Komondor(); System.out.println( mutt.getnumcreated() ); System.out.println( shaggy.getnumcreated() ); System.out.println( Mix.getNumCreated() ); System.out.println( Komondor.getNumCreated() ); Dog version Dog version Mix version Komondor version prints

124 What's Going On? there is no dynamic dispatch on static methods because the declared type of mutt is Dog, it is the Dog version of getnumcreated that is called because the declared type of shaggy is Dog, it is the Dog version of getnumcreated that is called 124

125 Hiding Methods notice that Mix.getNumCreated and Komondor.getNumCreated work as expected if a subclass declares a static method with the same name as a superclass static method, we say that the subclass static method hides the superclass static method you cannot override a static method, you can only hide it hiding static methods is considered bad form because it makes code hard to read and understand 125

126 the client code in WrongCount illustrates two cases of bad style, one by the client and one by the implementer of the Dog hierarchy 1. the client should not have used an instance to call a static method 2. the implementer should not have hidden the static method in Dog 126

127 127 Using superclass methods

128 Other Methods methods in a subclass will often need or want to call methods in the immediate superclass a new method in the subclass can call any public or protected method in the superclass without using any special syntax a subclass can override a public or protected method in the superclass by declaring a method that has the same signature as the one in the superclass a subclass method that overrides a superclass method can call the overridden superclass method using the super keyword 128

129 Dog equals we will assume that two Dogs are equal if their size and energy are the public boolean equals(object obj) { boolean eq = false; if(obj!= null && this.getclass() == obj.getclass()) { Dog other = (Dog) obj; eq = this.getsize() == other.getsize() && this.getenergy() == other.getenergy(); return eq; 129

130 Mix equals (version 1) two Mix instances are equal if their Dog subobjects are equal and they have the same public boolean equals(object obj) { // the hard way boolean eq = false; if(obj!= null && this.getclass() == obj.getclass()) { Mix other = (Mix) obj; subclass can call eq = this.getsize() == other.getsize() && public method of this.getenergy() == other.getenergy() && the superclass this.breeds.size() == other.breeds.size() && this.breeds.containsall(other.breeds); return eq; 130

131 Mix equals (version 2) two Mix instances are equal if their Dog subobjects are equal and they have the same breeds Dog equals already tests if two Dog instances are equal Mix equals can call Dog equals to test if the Dog subobjects are equal, and then test if the breeds are equal also notice that Dog equals already checks that the Object argument is not null and that the classes are the same Mix equals does not have to do these checks again 131

132 @Override public boolean equals(object obj) { boolean eq = false; subclass method that overrides a superclass if (super.equals(obj)) method can call the original superclass method { // the Dog subobjects are equal Mix other = (Mix) obj; eq = this.breeds.size() == other.breeds.size() && this.breeds.containsall(other.breeds); return eq; 132

133 Dog public String tostring() { String s = "size " + this.getsize() + "energy " + this.getenergy(); return s; 133

134 Mix public String tostring() { StringBuffer b = new StringBuffer(); b.append(super.tostring()); size and energy of the dog for(string s : this.breeds) breeds of the mix b.append(" " + s); b.append(" mix"); return b.tostring(); 134

135 Dog hashcode // similar to code generated by public int hashcode() { final int prime = 31; int result = 1; result = prime * result + this.getenergy(); result = prime * result + this.getsize(); return result; use this.energy and this.size to compute the hash code 135

136 Mix hashcode // similar to code generated by public int hashcode() { final int prime = 31; int result = super.hashcode(); result = prime * result + this.breeds.hashcode(); return result; use this.energy, this.size, and this.breeds to compute the hash code 136

137 Graphical User Interfaces notes Chap 7 137

138 Java Swing Swing is a Java toolkit for building graphical user interfaces (GUIs) old version of the Java tutorial had a visual guide of Swing components 6 tutorial/components.html 138

139 Simple Applications simple applications often consist of just a single window (containing some controls) JFrame window with border, title, buttons 139

140 Simple Applications simple applications can be implemented as a subclass of a JFrame hundreds of inherited methods but only a dozen or so are commonly called by the implementer (see URL below) Object Component Container Window Frame JFrame user interface item holds other components plain window window with title and border View 140

141 Simple Applications a simple application made up of a: JFrame has a JMenuBar has a Container (called the content pane) has a JLabel 141

142 Simple Applications a simple application made up of a: JFrame has a JMenuBar has a Container (called the content pane) 142 has a JLabel

143 Creating JFrames 1. Create the frame 2. Choose what happens when the frame closes 3. Create components and put them in the frame 4. Size the frame 5. Show it 143

144 public class ImageViewer extends JFrame implements ActionListener { // a unique identifier to associate with the Open command public static final String OPEN_COMMAND = "Open"; // a label to show the image private JLabel img; public ImageViewer() { // 1. Create the frame super("image Viewer"); // 2. Choose what happens when the frame closes this.setdefaultcloseoperation(jframe.exit_on_close); // 3. Create components and put them in the frame this.makemenu(); this.makelabel(); this.setlayout(new FlowLayout()); // 4. Size the frame this.setminimumsize(new Dimension(600, 400)); this.pack(); // 5. Show it this.setvisible(true); 144

145 public class ImageViewer extends JFrame implements ActionListener { // a unique identifier to associate with the Open command public static final String OPEN_COMMAND = "Open"; // a label to show the image private JLabel img; public ImageViewer() { // 1. Create the frame super("image Viewer"); // 2. Choose what happens when the frame closes this.setdefaultcloseoperation(jframe.exit_on_close); // 3. Create components and put them in the frame this.makemenu(); this.makelabel(); this.setlayout(new FlowLayout()); // 4. Size the frame this.setminimumsize(new Dimension(600, 400)); this.pack(); // 5. Show it this.setvisible(true); 145

146 public class ImageViewer extends JFrame implements ActionListener { // a unique identifier to associate with the Open command public static final String OPEN_COMMAND = "Open"; // a label to show the image private JLabel img; public ImageViewer() { // 1. Create the frame super("image Viewer"); // 2. Choose what happens when the frame closes this.setdefaultcloseoperation(jframe.exit_on_close); // 3. Create components and put them in the frame this.makemenu(); this.makelabel(); this.setlayout(new FlowLayout()); // 4. Size the frame this.setminimumsize(new Dimension(600, 400)); this.pack(); // 5. Show it this.setvisible(true); 146

147 public class ImageViewer extends JFrame implements ActionListener { // a unique identifier to associate with the Open command public static final String OPEN_COMMAND = "Open"; // a label to show the image private JLabel img; to respond to the user selecting the Open command from the menu public ImageViewer() { // 1. Create the frame super("image Viewer"); // 2. Choose what happens when the frame closes this.setdefaultcloseoperation(jframe.exit_on_close); // 3. Create components and put them in the frame this.makemenu(); this.makelabel(); this.setlayout(new FlowLayout()); // 4. Size the frame this.setminimumsize(new Dimension(600, 400)); this.pack(); // 5. Show it this.setvisible(true); controls how the components re size and re position when the JFrame changes size 147

148 public class ImageViewer extends JFrame implements ActionListener { // a unique identifier to associate with the Open command public static final String OPEN_COMMAND = "Open"; // a label to show the image private JLabel img; public ImageViewer() { // 1. Create the frame super("image Viewer"); // 2. Choose what happens when the frame closes this.setdefaultcloseoperation(jframe.exit_on_close); // 3. Create components and put them in the frame this.makemenu(); this.makelabel(); this.setlayout(new FlowLayout()); // 4. Size the frame this.setminimumsize(new Dimension(600, 400)); this.pack(); // 5. Show it this.setvisible(true); sizes the JFrame so that all components have their preferred size; uses the layout manager to help adjust component sizes 148

149 public class ImageViewer extends JFrame implements ActionListener { // a unique identifier to associate with the Open command public static final String OPEN_COMMAND = "Open"; // a label to show the image private JLabel img; public ImageViewer() { // 1. Create the frame super("image Viewer"); // 2. Choose what happens when the frame closes this.setdefaultcloseoperation(jframe.exit_on_close); // 3. Create components and put them in the frame this.makemenu(); this.makelabel(); this.setlayout(new FlowLayout()); // 4. Size the frame this.setminimumsize(new Dimension(600, 400)); this.pack(); // 5. Show it this.setvisible(true); 149

150 Labels a label displays unselectable text and images label JLabel label JLabel 150

151 private void makelabel() { this.img = new JLabel(""); this.getcontentpane().add(this.img); 151

152 Menus a menu appears in a menu bar (or a popup menu) each item in the menu is a menu item menu JMenu menu item JMenuItem menu bar JMenuBar JMenuBar + add(jmenu) * JMenu * + add(jmenuitem) JMenuItem 152

153 Menus to create a menu create a JMenuBar create one or more JMenu objects add the JMenu objects to the JMenuBar create one or more JMenuItem objectes add the JMenuItem objects to the JMenu 153

154 private void makemenu() { JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("File"); menubar.add(filemenu); JMenuItem openmenuitem = new JMenuItem("Open..."); openmenuitem.setactioncommand(imageviewer.open_command); openmenuitem.addactionlistener(this); filemenu.add(openmenuitem); this.setjmenubar(menubar); 154

155 private void makemenu() { JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("File"); menubar.add(filemenu); JMenuItem openmenuitem = new JMenuItem("Open..."); openmenuitem.setactioncommand(imageviewer.open_command); openmenuitem.addactionlistener(this); filemenu.add(openmenuitem); this.setjmenubar(menubar); 155

156 private void makemenu() { JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("File"); menubar.add(filemenu); JMenuItem openmenuitem = new JMenuItem("Open..."); openmenuitem.setactioncommand(imageviewer.open_command); openmenuitem.addactionlistener(this); filemenu.add(openmenuitem); this.setjmenubar(menubar); to respond to the user selecting the Open command from the menu 156

157 private void makemenu() { JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("File"); menubar.add(filemenu); JMenuItem openmenuitem = new JMenuItem("Open..."); openmenuitem.setactioncommand(imageviewer.open_command); openmenuitem.addactionlistener(this); filemenu.add(openmenuitem); this.setjmenubar(menubar); 157

158 Event Driven Programming so far we have a frame with some UI elements (menu, menu item, label) now we need to implement the actions each UI element is a source of events button pressed, slider moved, text changed, etc. when the user interacts with a UI element an event is triggered this causes an event object to be sent to every object listening for that particular event the event object carries information about the event the event listeners respond to the event 158

159 Not a UML Diagram event listener A event source 1 event object 1 event listener B event listener C event source 2 event object 2 event listener D 159

160 Implementation each JMenuItem has two inherited methods from AbstractButton public void addactionlistener(actionlistener l) public void setactioncommand(string actioncommand) for the JMenuItem 1. call addactionlistener with the listener as the argument 2. call setactioncommand with a string describing what event has occurred 160

161 Implementation our application has one event thiat is fired by a button (JMenuItem) a button fires an ActionEvent event whenever it is clicked ImageViewer listens for fired ActionEvents how? by implementing the ActionListener interface public interface ActionListener { void actionperformed(actionevent e); 161

162 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); if (result == JFileChooser.APPROVE_OPTION) { String filename = chooser.getselectedfile().getabsolutepath(); ImageIcon icon = new ImageIcon(fileName); if (icon.getimageloadstatus() == MediaTracker.COMPLETE) { this.img.seticon(icon); this.pack(); 162

163 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); to respond to the user if (result == JFileChooser.APPROVE_OPTION) { selecting the Open String filename = command from the menu chooser.getselectedfile().getabsolutepath(); ImageIcon icon = new ImageIcon(fileName); if (icon.getimageloadstatus() == MediaTracker.COMPLETE) { this.img.seticon(icon); this.pack(); 163

164 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); if (result == JFileChooser.APPROVE_OPTION) used to pick the { file String filename = to open chooser.getselectedfile().getabsolutepath(); ImageIcon icon = new ImageIcon(fileName); if (icon.getimageloadstatus() == MediaTracker.COMPLETE) { this.img.seticon(icon); this.pack(); 164

165 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); if (result == JFileChooser.APPROVE_OPTION) { String filename = show the file chooser and chooser.getselectedfile().getabsolutepath(); the user result (ok or ImageIcon icon = new ImageIcon(fileName); cancel) if (icon.getimageloadstatus() == MediaTracker.COMPLETE) { this.img.seticon(icon); this.pack(); 165

166 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); if (result == JFileChooser.APPROVE_OPTION) { String filename = chooser.getselectedfile().getabsolutepath(); user picked a file and ImageIcon icon = new ImageIcon(fileName); pressed ok if (icon.getimageloadstatus() == MediaTracker.COMPLETE) { this.img.seticon(icon); this.pack(); 166

167 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); if (result == JFileChooser.APPROVE_OPTION) { String filename = chooser.getselectedfile().getabsolutepath(); ImageIcon icon = new ImageIcon(fileName); if (icon.getimageloadstatus() == get the file name and MediaTracker.COMPLETE) directory { path that the this.img.seticon(icon); user picked this.pack(); 167

168 @Override public void actionperformed(actionevent e) { String command = e.getactioncommand(); if (command.equals(imageviewer.open_command)) { JFileChooser chooser = new JFileChooser(); int result = chooser.showopendialog(this); if (result == JFileChooser.APPROVE_OPTION) { String filename = chooser.getselectedfile().getabsolutepath(); ImageIcon icon = new ImageIcon(fileName); if (icon.getimageloadstatus() == MediaTracker.COMPLETE) try { to read the image this.img.seticon(icon); this.pack(); 168

Inheritance (cont) Abstract Classes

Inheritance (cont) Abstract Classes Inheritance (cont) Abstract Classes 1 Polymorphism inheritance allows you to define a base class that has fields and methods classes derived from the base class can use the public and protected base class

More information

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8 Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg

More information

Inheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8

Inheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8 Inheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8 1 Preconditions and Inheritance precondition what the method assumes to be true about the arguments passed to it inheritance (is-a) a subclass

More information

Inheritance (Part 2) Notes Chapter 6

Inheritance (Part 2) Notes Chapter 6 Inheritance (Part 2) Notes Chapter 6 1 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 2 Implementing Inheritance suppose you want to

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

More information

Based on slides by Prof. Burton Ma

Based on slides by Prof. Burton Ma Based on slides by Prof. Burton Ma 1 TV - on : boolean - channel : int - volume : int + power(boolean) : void + channel(int) : void + volume(int) : void Model View Controller RemoteControl + togglepower()

More information

EECS2030 Week 7 worksheet Tue Feb 28, 2017

EECS2030 Week 7 worksheet Tue Feb 28, 2017 1. Interfaces The Comparator interface provides a way to control how a sort method (such as Collections.sort) sorts elements of a collection. For example, the following main method sorts a list of strings

More information

Implementing Graphical User Interfaces

Implementing Graphical User Interfaces Chapter 6 Implementing Graphical User Interfaces 6.1 Introduction To see aggregation and inheritance in action, we implement a graphical user interface (GUI for short). This chapter is not about GUIs,

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

INHERITANCE. Spring 2019

INHERITANCE. Spring 2019 INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

More information

Review sheet for Final Exam (List of objectives for this course)

Review sheet for Final Exam (List of objectives for this course) Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions Exam information in lab Tue, 18 Apr 2017, 9:00-noon programming part from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017 Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008 Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Graphical User Interfaces. Comp 152

Graphical User Interfaces. Comp 152 Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

More Data Structures (Part 1) Stacks

More Data Structures (Part 1) Stacks More Data Structures (Part 1) Stacks 1 Stack examples of stacks 2 Top of Stack top of the stack 3 Stack Operations classically, stacks only support two operations 1. push 2. pop add to the top of the stack

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

More Relationships Between Classes

More Relationships Between Classes More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to

More information

First IS-A Relationship: Inheritance

First IS-A Relationship: Inheritance First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide Topics for Exam 2: Queens College, CUNY Department of Computer Science CS 212 Object-Oriented Programming in Java Practice Exam 2 CS 212 Exam 2 Study Guide Linked Lists define a list node define a singly-linked

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Chapter 10 Classes Continued. Fundamentals of Java

Chapter 10 Classes Continued. Fundamentals of Java Chapter 10 Classes Continued Objectives Know when it is appropriate to include class (static) variables and methods in a class. Understand the role of Java interfaces in a software system and define an

More information

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

COMP 250 Fall inheritance Nov. 17, 2017

COMP 250 Fall inheritance Nov. 17, 2017 Inheritance In our daily lives, we classify the many things around us. The world has objects like dogs and cars and food and we are familiar with talking about these objects as classes Dogs are animals

More information

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes CS/ENGRD 2110 FALL 2017 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due tomorrow night (17 February) Get started on A3 a method every other day.

More information

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes. a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces what is inheritance? examples & Java API examples inheriting a method overriding a method polymorphism Object tostring interfaces Ex: sorting and Comparable interface Inheritance

More information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes CS/ENGRD 2110 SPRING 2019 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due Thursday night (14 February) Go back to Lecture 6 & discuss method

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Inheritance. Chapter 7. Chapter 7 1

Inheritance. Chapter 7. Chapter 7 1 Inheritance Chapter 7 Chapter 7 1 Introduction to Inheritance Inheritance allows us to define a general class and then define more specialized classes simply by adding new details to the more general class

More information

Lecture Notes Chapter #9_b Inheritance & Polymorphism

Lecture Notes Chapter #9_b Inheritance & Polymorphism Lecture Notes Chapter #9_b Inheritance & Polymorphism Inheritance results from deriving new classes from existing classes Root Class all java classes are derived from the java.lang.object class GeometricObject1

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Polymorphism. return a.doublevalue() + b.doublevalue();

Polymorphism. return a.doublevalue() + b.doublevalue(); Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 March 23, 2016 Inheritance and Dynamic Dispatch Chapter 24 Inheritance Example public class { private int x; public () { x = 0; } public void incby(int

More information

We are on the GUI fast track path

We are on the GUI fast track path We are on the GUI fast track path Chapter 13: Exception Handling Skip for now Chapter 14: Abstract Classes and Interfaces Sections 1 9: ActionListener interface Chapter 15: Graphics Skip for now Chapter

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

CS Exam 1 Review Suggestions

CS Exam 1 Review Suggestions CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) ) COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) ) Course Evaluations Please do these. -Fast to do -Used to

More information

Java Classes, Inheritance, and Interfaces

Java Classes, Inheritance, and Interfaces Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

Introduction to Inheritance

Introduction to Inheritance Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, Polymorphism, and Interfaces Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)

More information

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1 Inheritance & Polymorphism Recap Inheritance & Polymorphism 1 Introduction! Besides composition, another form of reuse is inheritance.! With inheritance, an object can inherit behavior from another object,

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

Full file at Chapter 2 - Inheritance and Exception Handling

Full file at   Chapter 2 - Inheritance and Exception Handling Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

a correct statement? You need to know what the statement is supposed to do.

a correct statement? You need to know what the statement is supposed to do. Using assertions for correctness How can we know that software is correct? It is only correct if it does what it is supposed to do. But how do we know what it is supposed to do? We need a specification.

More information

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass? 1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type

More information

Advanced Placement Computer Science. Inheritance and Polymorphism

Advanced Placement Computer Science. Inheritance and Polymorphism Advanced Placement Computer Science Inheritance and Polymorphism What s past is prologue. Don t write it twice write it once and reuse it. Mike Scott The University of Texas at Austin Inheritance, Polymorphism,

More information

Building Graphical User Interfaces. Overview

Building Graphical User Interfaces. Overview Building Graphical User Interfaces 4.1 Overview Constructing GUIs Interface components GUI layout Event handling 2 1 GUI Principles Components: GUI building blocks. Buttons, menus, sliders, etc. Layout:

More information

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by

More information

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 SPRING 2018 CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,

More information

Building Graphical User Interfaces. GUI Principles

Building Graphical User Interfaces. GUI Principles Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting

More information

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Constructor Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design these classes so to avoid redundancy? The

More information

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

CS 215 Software Design Sample midterm solutions

CS 215 Software Design Sample midterm solutions Software Design Sample midterm solutions 1. The administration at Happy Valley School District is redesigning the software that manages information about its students. It has identified an abstract class

More information

CSE wi Final Exam 3/12/18. Name UW ID#

CSE wi Final Exam 3/12/18. Name UW ID# Name UW ID# There are 13 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,

More information

Chapter 5. Inheritance

Chapter 5. Inheritance Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Inheritance (continued) Inheritance

Inheritance (continued) Inheritance Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

Subtypes and Subclasses

Subtypes and Subclasses Subtypes and Subclasses 6.170 Lecture 14 Fall - ocw.mit.edu Reading: Chapter 7 of Program Development in Java by Barbara Liskov 1 Subtypes We have used closed arrows in module dependence diagrams and object

More information

C12a: The Object Superclass and Selected Methods

C12a: The Object Superclass and Selected Methods CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Recitation 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University Project 5 Due Wed, Oct. 22 at 10 pm. All questions on the class newsgroup. Make use of lab

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling Overview Building Graphical User Interfaces Constructing GUIs Interface components GUI layout Event handling 4.1 GUI Principles AWT and Swing Components: GUI building blocks. Buttons, menus, sliders, etc.

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

CS159. Nathan Sprague

CS159. Nathan Sprague CS159 Nathan Sprague What s wrong with the following code? 1 /* ************************************************** 2 * Return the mean, or -1 if the array has length 0. 3 ***************************************************

More information

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012 Why Design by Contract What s the difference with Testing? CS 619 Introduction to OO Design and Development Design by Contract Fall 2012 Testing tries to diagnose (and cure) defects after the facts. Design

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Making New instances of Classes

Making New instances of Classes Making New instances of Classes NOTE: revised from previous version of Lecture04 New Operator Classes are user defined datatypes in OOP languages How do we make instances of these new datatypes? Using

More information

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Prototyping a Swing Interface with the Netbeans IDE GUI Editor Prototyping a Swing Interface with the Netbeans IDE GUI Editor Netbeans provides an environment for creating Java applications including a module for GUI design. Here we assume that we have some existing

More information

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information