
Inheritance -
Review
Object-oriented programming

Expressions
Inheritance 2
"interface"
Expression
+ asString(): String
+ evaluate(): int
"interface"
BinaryExpression
+ left(): Expression
+ right(): Expression
Numeral
- int: value
+ Numeral(int)
+ Numeral() Square
- Expression: expression
+ Square(Expression)
Addition
- Expression: left
- Expression: right
+ Addition(Expression, Expression)

Inheritance 33
Generic Stack
...
MyStack s = new MyStack();
Point p = new Point();
Circle c = new Circle();
s.push(p);
s.push(c);
Circle c1 = (Circle) s.pop();
Point p1 = (Point) s.pop();
class MyStack {
...
public void push(Object obj) {...}
public Object pop() {...}
}

Generic List
Inheritance 4
MyList l = new MyList();
l.append(1);
l.append(2);
System.out.println(l); // (1, 2)
MyList l2 = new MyList();
l2.append(3);
l2.append(4);
System.out.println(l2); // (3, 4)
l.append(l2);
System.out.println(l); // (1, 2, (3, 4))
l.appendList(l2);
System.out.println(l); // (1, 2, (3, 4), 3, 4)
l2.append(5);
System.out.println(l); // (1, 2, (3, 4, 5), 3, 4)
Node
+ data: Object
+ next: Node
+ Node(Object, Node)
MyList
- Node: start
- Node: end
+ MyList ()
+ append(Object)
+ appendList(MyList)
+ toString(): String
start
end

Generic List
Problem!!!
l.append(l)
Inheritance 5

