intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Inheritance Review_Object-oriented programming

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

76
lượt xem
3
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

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ủ đề:
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
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2