Inheritance - Review Object-oriented programming... Generic ListProblem!!!. l.appendl.
Trang 1Inheritance -
Review
Object-oriented programming
Trang 2Expressions "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)
Trang 3Generic List
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)
Node
+ data: Object + next: Node + Node(Object, Node)
MyList
- Node: start
- Node: end + MyList () + append(Object) + appendList(MyList) + toString(): String
start
end
Trang 4Generic List
Problem!!!
l.append(l)
Trang 5Better List
Node
+ data: Item
+ next: Node
+ Node(Item, Node)
MyList
- Node: start
- Node: end
+ MyList ()
+ append(Item)
+ appendList(MyList)
"Interface"
Item
+ clone(): Item + toString(): String
NumeralItem
- int: value + NumeralItem(int)
StringItem
- String: value + StringItem(int)