# Inheritance Review_Object-oriented programming

Chia sẻ: Nguyen Phong | Ngày: | Loại File: PPT | Số trang:6

0
55
lượt xem
3

## Inheritance Review_Object-oriented programming

Mô tả tài liệu

Inheritance Review Object-oriented programming .Expressions Numeral - int: value + Numeral(int) + Numeral() "interface" Expression + asString(): String + evaluate(): int Square - Expression: expression + Square(Expression) "interface"

Chủ đề:

Bình luận(0)

Lưu

## Nội dung Text: Inheritance Review_Object-oriented programming

1. Inheritance - Review Object-oriented programming
2. Expressions "interface" Expression + asString(): String + evaluate(): int Numeral - int: value + Numeral(int) "interface" + Numeral() BinaryExpression Square - Expression: expression + Square(Expression) + left(): Expression + right(): Expression Addition - Expression: left - Expression: right + Addition(Expression, Expression) Inheritance 2
3. Generic Stack class MyStack { ... public void push(Object obj) {...} public Object pop() {...} } ... 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(); Inheritance 3
4. Node start Generic List + data: Object + next: Node + Node(Object, Node) MyList - Node: start end - Node: end + MyList () + append(Object) MyList l = new MyList(); + appendList(MyList) l.append(1); + toString(): String 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) Inheritance 4
5. Generic List Problem!!! l.append(l) Inheritance 5
6. Better List Node + data: Item + next: Node + Node(Item, Node) "Interface" Item + clone(): Item + toString(): String MyList - Node: start - Node: end NumeralItem StringItem + MyList () + append(Item) - int: value - String: value + appendList(MyList) + NumeralItem(int) + StringItem(int) Inheritance 6