Lecture 12: Abstract Data Types(ADT)

1 What Abstraction Means

Here are some of the names that are used for Abstract Data Types:

  • Abstraction
  • Modularity
  • Encapsulation
  • Information hiding
  • Separation of concerns

1.1 User-Defined Types

  • The key idea of data abstraction is that a type is characterized by the operations you can perform on it.
  • The user of the type would not need to worry about how its values were actually stored.

2 Classifying Types and Operations

  • Creators create new objects of the type. A creator may take an object as an argument, but not an object of the type being constructed.
    • A creator operation is often implemented as a constructor, like new ArrayList()
    • A creator can simply be a static method instead, like Arrays.asList(). A creator implemented as a static method is often called a factory method.
  • Producers create new objects from old objects of the type. The concat method of String , for example, is a producer: it takes two strings and produces a new one representing their concatenation.
  • Observers take objects of the abstract type and return objects of a different type. The size method of List , for example, returns an int.
  • Mutators change objects. The add method of List , for example, mutates a list by adding an element to the end.
    • Mutators are often signaled by a void return type. A method that returns void must be called for some kind of side-effect, since otherwise it doesn’t return anything.
    • Not all mutators return void. For example, Set.add() returns a boolean that indicates whether the set was actually changed. In Java’s graphical user interface toolkit, Component.add() returns the object itself, so that multiple add() calls can be chained together.

3 Designing an Abstract Type

  • It’s better to have a few, simple operations that can be combined in powerful ways, rather than lots of complex operations.
  • Each operation should have a well-defined purpose, and should have a coherent behavior rather than a panoply of special cases.
  • The set of operations should be adequate in the sense that there must be enough to do the kinds of computations clients are likely to want to do.
  • It should not mix generic and domain-specific features.
    A Deck type intended to represent a sequence of playing cards shouldn’t have a generic add method that accepts arbitrary objects like integers or strings. Conversely, it wouldn’t make sense to put a domain-specific method like dealCards into the generic type List.

4 Representation Independence

  • Representation independent means that the use of an abstract type is independent of its representation (the actual data structure or data fields used to implement it), so that changes in representation have no effect on code outside the abstract type itself.

Reference

[1] 6.005 — Software Construction on MIT OpenCourseWare | OCW 6.005 Homepage at https://ocw.mit.edu/ans7870/6/6.005/s16/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值