基于对象的(Object-based)和面向对象的(Object-oriented)有何联系区别?

基于对象(OB)和面向对象(OO)是两个极易混淆的概念。两者的区别是多态,和继承无关。

面向对象(OB),用纯粹的理论去理解就是,必须具备封装、继承、多态三大特点,缺一不可。可以根据对象的实际类型不同,可以自动完成不同的行为,而仅仅通过一致的调用形式(多态)。
基于对象 (OO),仅仅支持抽象数据类型的功能(ADT),通常指的是对数据和操作的封装。无法利用现有的对象模板产生新的对象模型,继而产生新的对象,也就是说“基于对象”没有继承的特点,而多态是表示为父类类型的子类对象实例,没有继承,就更不用说多态了。

面向对象的三个特性之间的关系:没有封装,就不能继承,不能继承就没有运行时的多态。

一个OB设计可能比一个对等的OO设计速度更快而且空间更紧凑。
速度快是因为所有的函数调用操作都在编译时期解析完成,对象建构起来时不需要设置virtual机制;
空间紧凑则是因为每一个class object不需要负担传统上为了支持virtual机制而需要的额外负荷。
虽然C++通过class的pointer和references来支持多态,但是需要付出的代价就是额外的间接性——不论是在“内存的获得”或是在“类型的决断”上。

但是,OB设计比较没有弹性。
因为OB不支持类型的扩充,而OO可以利用现有的对象模板产生新的对象类型,继而产生新的对象,也就是“继承”。

在弹性(OO)和效率(OB)之间常常存在着取与舍。效选择其一之前,必须先了解清楚两者的行为和应用领域的需求。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
中文名: Beginning C# Object-Oriented Programming (第1版, 涵盖.NET 4.0 and C# 4.0) 原名: Beginning C# Object-Oriented Programming, 1st edition 作者: Dan Clark 资源格式: PDF 出版社: Apress书号: 978-1430235309发行时间: 2011年05月31日 地区: 美国 语言: 英文 简介: 内容介绍: Beginning C# Object-Oriented Programming brings you into the modern world of development as you master the fundamentals of programming with C# and learn to develop efficient, reusable, elegant code through the object-oriented programming (OOP) methodology. Take your skills out of the 20th century and into this one with Dan Clark's accessible, quick-paced guide to C# and object-oriented programming, completely updated for .NET 4.0 and C# 4.0. As you develop techniques and best practices for coding in C#, one of the world's most popular contemporary languages, you'll experience modeling a “real world” application through a case study, allowing you to see how both C# and OOP (a methodology you can use with any number of languages) come together to make your code reusable, modern, and efficient. With more than 30 fully hands-on activities, you'll discover how to transform a simple model of an application into a fully-functional C# project, including designing the user interface, implementing the business logic, and integrating with a relational database for data storage. Along the way, you will explore the .NET Framework, the creation of a Windows-based user interface, a web-based user interface, and service-oriented programming, all using Microsoft's industry-leading Visual Studio 2010, C#, Silverlight, the Entity Framework, and more. 目录: Overview of Object-Oriented Programming Designing OOP Solutions: Identifying the Class Structure Designing OOP Solutions: Modeling the Object Interaction Designing OOP Solutions: A Case Study Introducing the .NET Framework and Visual Studio Creating Classes Creating Class Hierarchies Implementing Object Collaboration Working with Collections Implementing the Data Access Layer Developing Windows Applications Developing Web Applications Developing and Consuming WCF Services Developing the OSO Application Wrapping Up Fundamental Programming Concepts Exception Handling in C# Installing the Required Software

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值