问题描述
我大学二年级的学生.....我的任务是..
是否真的可以在C中编写面向对象的代码?
如果是,我们如何实现abstration,多态性,层次结构等。
in C
system(" g ++ -o foo foo.cpp");
我不希望100%否定,所以我应该指出,通过使用opaque类型,你可以毫不费力地获得数据隐藏和封装。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 1999年7月29日
发送电子邮件至上述域名
有两种抽象:
1.)算法抽象和
2.)数据抽象。
算法抽象是指语言特征
允许你创建子程序
(子程序,程序,函数等)
这是独立的,可重复使用的模块。
原始达特茅斯BASIC
不支持算法抽象
但大多数其他高级计算机编程语言都有。
数据抽象是指语言功能
允许您创建新的用户定义类型(UDT)。
标准Fortran 77不支持数据抽象
但大多数现代高级计算机编程语言都支持。
C计算机编程语言允许你创建UDT
*通过*封装*结构中的其他数据类型
但C不*支持数据隐藏 - 私有数据成员。 />
注意 - 对于一些面向对象的程序员,
封装意味着数据隐藏。
数据隐藏不*意味着加密。
没有办法隐藏数据表示
,只有几个简单的测试,一个坚定的程序员不能公开
。
数据隐藏只是为了防止程序员意外地直接访问实际的数据表示。
C计算机编程语言*不支持继承。
指向派生类型的指针需要明确的种姓
指向基本类型的指针。
C程序员一直在使用运行时多态性
,只要有C程序员。
标准文件例如,ype是一种多态类型。
i m a college student in my second year.....
my queston is..
is it really possible to write object oriented code in C ?
and if yes how do we achieve abstration, polymorhism , hierarchy etc.
in C
system("g++ -o foo foo.cpp");
I don''t wish to be 100% negative, so I should point out that you can get
data hiding and encapsulation fairly painlessly by using opaque types.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29 July 1999
http://www.cpax.org.uk
Email rjh at the above domain
There are two kinds of abstraction:
1.) algorithmic abstraction and
2.) data abstraction.
Algorithmic abstraction refers to language features
that allow you to create subprograms
(subroutines, procedures, functions, etc.)
which are independent, reusable modules.
The original Dartmouth BASIC
did not support algorithmic abstraction
but most other high level computer programming languages do.
Data abstraction refers to language features
that allow you to create new, User Defined Types (UDTs).
Standard Fortran 77 does not support data abstraction
but most modern high level computer programming languages do.
The C computer programming language allows you to create UDTs
by *encapsulating* other data types in a struct
but C does *not* support data hiding -- private data members.
Beware -- for some object oriented programmers,
encapsulation implies data hiding.
Data hiding does *not* mean encryption.
There is no way to hide the data representation
which a determined programmer can''t expose
with just a few simple tests.
Data hiding is intended only to prevent programmers
from accidently accessing the actual data representation directly.
The C computer programming language does *not* support inheritance.
An explicit caste is required of a pointer to a derived type
to a pointer of the base type is required.
C programmers have been using run-time polymorphism
as long as there have been C programmers.
The standard FILE type, for example, is a polymorphic type.
这篇关于面向对象.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!