为什么要使用类? [英] Why Use Classes?

查看:124
本文介绍了为什么要使用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


我是C ++的新手,但已经编写了其他几种语言,而且b $ b发现大部分c ++相当容易(到目前为止!) 。


我来到课程教程,有人可以告诉我为什么

你需要上课吗?


也许你也可以举例说明何时可以使用它而不是另一种方法




谢谢你提前帮助。


Langy。

解决方案

2004年10月24日13:23:16 -0700 , la******@hotmail.com (Langy)写道:

你好

我是C ++的新手,但已编写了其他几种语言,并且发现大多数c ++相当容易(到目前为止!)。
我来到课程教程,有人可以告诉我为什么
你需要上课吗?


做任何其他语言有一个面向对象的编程

范例?可能更容易理解C ++类是什么/可以做什么

如果你已经知道的其他语言有类似的功能。

也许你也可以给一个关于什么时候使用它而不是替代方法的例子。

提前感谢您的帮助。

Langy。




-

Bob Hairgrove
否* *********@Home.com




" Langy" < LA ****** @ hotmail.com>在消息中写道

新闻:b6 ************************* @ posting.google.co m ... < blockquote class =post_quotes>你好

我是C ++的新手,但已编写了其他几种语言,并且发现大部分c ++都相当容易(到目前为止!)。

我来过课程教程,有人可以告诉我为什么
你需要上课吗?

也许你也可以给一个例子什么时候可以使用它而不是替代方法。

提前感谢您的帮助。

Langy。




我喜欢使用类主要是出于以下原因:

*它们提供数据和函数之间的逻辑连接,这些数据和函数在

上运行该数据。

*您可以使用虚拟函数创建可以节省编码并且可以扩展的类层次结构。

*您可以限制对数据的访问,删除错误的机会,直接

访问可以giv e。


PKH


Langy写道:

你好

我是C ++的新手,但已编写了其他几种语言,并且发现大多数c ++相当容易(到目前为止!)。


容易吗?你走得远吗? ;-)与其他

语言相比,我不会说容易。 c ++掌握着你的力量,但你需要应付力量。

我已经上了课程教程,有人可以告诉我为什么你需要使用类?


它为您提供了很好的抽象功能。你可以设计内部状态和

应该在一大块代码中修改状态的操作。在

中你可以隐藏你的对象状态的表示

在它的界面后面,这允许你修改表示而不用

破坏与客户端的接口使用修改后的代码,这对于编写大型演进系统非常重要。

一旦你用面向对象的范例编写了一些时间,你就学会了

看到重复出现的抽象模式,你可以重新申请其他问题,

从长远来看,你可以让你成为一个更高效的程序员。你会更快地理解

别人的代码。

有很棒的C程序员(或程序程序员那个

)将编码比一些C ++程序员更好,你可以用面向对象的方式编写代码(例如使用函数指针来实现多态性),但语法特征和语言本身对语言本身的OO支持,可以编写更具凝聚力的程序和

来更快地理解其他程序。

也许你还可以给出一个例子,说明何时使用它而不是替代方法。
我知道我之前所说的听起来很抽象,但我会说服你学习

oo-features。从长远来看,我敢肯定你会想知道为什么你可以这么长时间没有它们。当然,当你开始维护或者说b
编程时需要20个源文件。
感谢您的帮助。

Langy。



Hello

I''m fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!).

I''ve come to a tutorial on classes, could someone please tell me why
you would need to use a class?

Perhaps you could also give an example on when it might be used rather
than an alternative method.

Thanks for your help in advance.

Langy.

解决方案

On 24 Oct 2004 13:23:16 -0700, la******@hotmail.com (Langy) wrote:

Hello

I''m fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!). I''ve come to a tutorial on classes, could someone please tell me why
you would need to use a class?
Do any of the "other languages" have an object-oriented programming
paradigm? It might be easier to understand what a C++ class is/can do
if one of the other languages you already know has a similar feature.
Perhaps you could also give an example on when it might be used rather
than an alternative method.

Thanks for your help in advance.

Langy.



--
Bob Hairgrove
No**********@Home.com



"Langy" <la******@hotmail.com> wrote in message
news:b6*************************@posting.google.co m...

Hello

I''m fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!).

I''ve come to a tutorial on classes, could someone please tell me why
you would need to use a class?

Perhaps you could also give an example on when it might be used rather
than an alternative method.

Thanks for your help in advance.

Langy.



I like using classes primarily for the following reasons:
* They provide a logical connection between data and functions operating on
that data.
* You can make class-hierarchies which can save coding and are very
extendable by using virtual functions.
* You can restrict access to data, removing bug-opportunities that direct
access could give.

PKH


Langy wrote:

Hello

I''m fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!).
easy? have you gone far? ;-) i wouldn''t say easy compared to other
languages. c++ is power in your hands, but you need to cope with power.

I''ve come to a tutorial on classes, could someone please tell me why
you would need to use a class?
it gives you nice abstraction features. you can design internal state and
the operations which should modify the state in a nice chunk of code. In
addition you can hide the representation of the state of your objects
behind its interface, which allows you to modify the representation without
breaking the interface with clients using the modified code, which is
extremely important when you program large evolving systems.
once you have coded some time with object-oriented paradigm, you learn to
see recurring abstract patterns, which you can reapply for other problems,
making you a more productive programmer in long run. you will understand
someone else''s code more quickly.
there are fantastic C programmers (or procedural programmers for that
matter) which will code better than some C++ programmers and you can code
in an object oriented manner with C (for example using function pointers to
implement polymorphism), but the syntactical features and support for OO in
the language itself, makes it possible to code more cohesive programs and
to understand other programs more quickly.

Perhaps you could also give an example on when it might be used rather
than an alternative method. i know what i said before sounds abstract, but i''d convince you to learn the
oo-features. in the long run, i''m sure you will once wonder why you could
do without them for so long; certainly when you start maintaining or
programming proggies with say 20 source files.
Thanks for your help in advance.

Langy.




这篇关于为什么要使用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆