Showing posts with label Object Design. Show all posts
Showing posts with label Object Design. Show all posts

26.7.10

Some discussions on Bag and Stack

In general, Bag doesn't implies a sequenced structure (of course you can use a list to implement the internal structure, but not all the Bag does). Hence, it is possible that after we put a series of objects to the Bag, we cannot get them back in the sequence we expected, in fact, we lost the sequence. Therefore, a Bag may not necessary able to perform all the tasks done by a Stack.

But it's true that many programmers in the market work around with their data structure as you did. They use a list to store objects and implement bag alike methods, with put() where they can specify the exact location to store the object, but this is not simply a Bag anymore.

26.4.07

Delegation, Object composition and Has-a relationship

Delegation or Object composition is a way to construct the has-a relationships.

Why the subclass cannot strengthen the precondition?

Subclass can strengthen the invariants and postconditions of the inherited contract and can only weaken its preconditions. This is because if the precondition of the subclass method is strengthened, the method will not able to execute if a superclass is being substituted with the subclass. So we can only weaken its preconditions.