从计算机程序的内部实现来说,似乎一致性可以分为三种途径,硬一致,抽象数据类型一致,软一致。
(1) 硬一致(hard consistency)。不涉及数据类型的抽象,全部的数据跑过的代码基本相同,不同的数据仅仅只有输出层面的不同,没有逻辑上的实质的不同。例如:
int do_animal_hello(const char * a){
printf("Hello, this is %s", a);
}
// do_animal_hello("Tiger") 输出 Hello, this is Tiger
// do_animal_hello("Dog") 输出 Hello, this is Dog
(2) 抽象数据类型一致(abstract data type consistency)。数据抽象可以分为共有部分和扩展部分,不同的数据可能会因为共有部分的不同而行为不同,并且可能进一步地使用了扩展部分的数据,而实现更丰富的行为。例如:
int do_animal_hello(struct animal * a){
printf("Hello, this is %s. ", a->title);
if(a->family == Felidae){
printf("My mustache is %dcm.", a->length_mustache)
} else if(a->Family == Canidae){
printf("I have %d teeth.", a->number_teeth)
}
}
// do_animal_hello("Tiger") 输出 Hello, this is Tiger. My mustache is 15cm.
// do_animal_hello("Dog") 输出 Hello, this is Dog. I have 28 teeth.
(3) 软一致(soft consistency)。不依赖一个数据之间的共有域,数据是最不受限制的,程序将不同内容不同性质不同意义的数据整理为了看似一致的样式,并提供了看似一致的能力。
int do_hello(int a, struct ext_animal *ea){
if(ea == NULL){
printf("Hello, this is Tiger. My mustache is %dcm.", a);
} else if (ea->mode1 == 1) {
printf("Hello, this is Dog. I have %d teeth.", ea->teeth);
}
}
// do_hello(15, NULL) 输出 Hello, this is Tiger. My mustache is 15cm.
// do_hello(0, ea1) 输出 Hello, this is Dog. I have 28 teeth.
一些程序看似怪异,似乎就在于,由于历史原因,他们只能是通过某种奇特的软一致的方式实现了,并且仍然是较为适合的方式。
--
FROM 117.136.0.*