[問題] Abstract data type與物件的關係?
嗨,魯蛇我看到維基百科對於ADT的描述有點不清楚,故上來發文請教。
網址: https://en.wikipedia.org/wiki/Abstract_data_type
In computer science, an abstract data type (ADT) is a mathematical model for
data types, where a data type is defined by its behavior (semantics) from the
point of view of a user of the data, specifically in terms of possible
values, possible operations on data of this type, and the behavior of these
operations.
我有查過stack overflow關於ADT的定義,讀完之後,想法是:
我定義一個全新的資料型別,這個資料型別的"概念"是可以放很多相同型別變數的容器,
而我要求在C語言中(我只會C,所以拿C當例子),創造這個變數的方式(semantic)是:
容器裡的資料型別 容器名字[容量];,for example:
int array[3];
同時我定義中括號裡面的數字為下標,下標可以代表每個在容器裡面的資料的index,同時
也定義如何對這個容器做operation(把容器當作參數丟到function裡、利用指標操作容器)
那麼,這整個東西叫一個ADT,實作出來的叫CDT(concrete data type),也就是array。
我會問這個問題是因為我不太清楚ADT與物件之間的關係。
我現在想要用C實作一個battery的物件,那我要先定義這個battery要用什麼data type表
示、會有什麼行為,那我感覺ADT非常相似於物件,但又感覺有一些差別。
拿個實際我卡住的例子:
typedef enum{
BATTERY_UNLOAD,
BATTERY_LOADED,
BATTERY_HEALTHY,
BATTERY_BROKEN,
}BATTERY_STATES;
typedef struct{
uint16_t voltage;
uint16_t current;
uint16_t temperature;
BATTERY_STATES battery_state;
}BATTERY_OBJECT;
在這個例子中,我定義了battery的語意、也定義了battery的operation(可以被指標處理)
,那這不就等於ADT嗎?
如果我今天改成用queue放資料:
typedef struct{
queueNode QueueNode;
BATTERY_STATES battery_state;
}BATTERY_OBJECT;
那麼,物件就不等於ADT了,因為ADT被包含在物件裡。
那請問,我這篇文章在觀念上哪邊有錯誤嗎?
如果沒有錯誤,那麼,物件與ADT之間的關係是?
謝謝各位前輩指教。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.26.157
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1520826872.A.20D.html
推
03/12 12:50,
8年前
, 1F
03/12 12:50, 1F
→
03/12 12:51,
8年前
, 2F
03/12 12:51, 2F
→
03/12 12:51,
8年前
, 3F
03/12 12:51, 3F
→
03/12 12:52,
8年前
, 4F
03/12 12:52, 4F
→
03/12 12:52,
8年前
, 5F
03/12 12:52, 5F
→
03/12 12:52,
8年前
, 6F
03/12 12:52, 6F
→
03/12 12:52,
8年前
, 7F
03/12 12:52, 7F
→
03/12 12:54,
8年前
, 8F
03/12 12:54, 8F
→
03/12 12:54,
8年前
, 9F
03/12 12:54, 9F
→
03/12 12:55,
8年前
, 10F
03/12 12:55, 10F
→
03/12 12:57,
8年前
, 11F
03/12 12:57, 11F
→
03/12 12:57,
8年前
, 12F
03/12 12:57, 12F
→
03/12 12:58,
8年前
, 13F
03/12 12:58, 13F
→
03/12 12:59,
8年前
, 14F
03/12 12:59, 14F
→
03/12 13:01,
8年前
, 15F
03/12 13:01, 15F
→
03/12 13:01,
8年前
, 16F
03/12 13:01, 16F
→
03/12 13:07,
8年前
, 17F
03/12 13:07, 17F
→
03/12 13:09,
8年前
, 18F
03/12 13:09, 18F
→
03/12 14:11,
8年前
, 19F
03/12 14:11, 19F
→
03/12 14:13,
8年前
, 20F
03/12 14:13, 20F
→
03/12 14:14,
8年前
, 21F
03/12 14:14, 21F
不好意思,順便借問一下,Horowitz的fundamentals of data structures第一版(1981)與
第二版(2007)的內容會差很多嗎?我手頭只有第一版
※ 編輯: zzss2003 (60.248.26.157), 03/12/2018 15:39:39
→
03/12 15:53,
8年前
, 22F
03/12 15:53, 22F
謝啦~那我去買個第二版來讀好了
※ 編輯: zzss2003 (60.248.26.157), 03/12/2018 16:23:54
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章