类模式和对象模式 [英] class pattern and object pattern

查看:286
本文介绍了类模式和对象模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是设计模式的新手,并且没有多少经验。我对目标模式和类感到困惑。我注意到的一个区别是类模式使用继承和对象模式使用组合。我正在使用c ++,所以让我知道c ++支持对象/类模式,在GOF中的SInce,没有明确的解释。



我的问题是为什么使用类模式和对象模式以及何时使用以及它在哪里使用。我对此非常陌生。请用简单的方式告诉我。例如。

I am new to design pattern and donot have much experience in it .I am confused with object pattern and class .one difference i noticed is class pattern uses inheritence and object pattern uses composition.I am working on c++ ,so let me know c++ support object/class pattern ,SInce in the Book GOF ,there is not having clear explanation .

my question is why class pattern and object pattern is used and when and where it is used .As i am very new to this .please let me know in simple ,with example.

推荐答案

正如SA所说,这些模式无论如何,不​​是正式的。如果您正在阅读的文章或书籍使用这些术语,则可能会自行创造它们,并应提供定义。但这些不是你可以在GoF书中找到的设计模式,也不是C ++术语中的任何官方术语。



对象的官方含义在C ++的上下文中是一个类的实例化。将模式附加到类或对象因此对我来说没有多大意义。我建议你得到一些更好的文章/书,实际上使用官方术语,而不是通过使用自己的混淆人。由以下任何作者检查书籍(无特定顺序):



- Bjarne Stroustrup

- Andrei Alexandrescu

- Herb Sutter



我个人认为Stroustrup对于初学者来说更容易阅读,但其他人真的有助于掌握语言中更复杂的方面一旦你准备好了。



还有其他非常优秀的作者,但恕我直言,如果你还没有读过这些作品你就不懂C ++三位作者!





As SA has stated, these "patterns" do not mean anything, not officially anyway. If an article or book you are reading uses these terms, it has likely coined them itself, and should provide the definitions. But these are not design patterns that you can find in the GoF book, nor are they in any way official terms from the C++ terminology.

The official meaning of "object" in the context of C++ is the instantiation of a class. attaching "pattern" to either "class" or "object" therefore doesn't make a lot of sense to me. I suggest you get some better article/book that actually uses the official terminology rather than confusing people by using their own. Check on books by any of the following authors (in no particular order):

- Bjarne Stroustrup
- Andrei Alexandrescu
- Herb Sutter

Personally I find Stroustrup a bit easier read for beginners, but the others really help to get the hang of more complex aspects of the language once you're ready for that.

There are other very good authors as well, but IMHO you don't know C++ if you haven't read works from these three authors!


引用:

一我注意到的差异是类模式使用继承和对象模式使用组合

one difference i noticed is class pattern uses inheritence and object pattern uses composition



忘记这些模式术语。继承是面向对象编程(OOP)的基石,而组合是程序编程中使用的基本元素。搜索编程范例时,可以找到有关此内容的更多信息。在这种情况下,术语模式完全是错误的!


Forget these "pattern" terms. Inheritance is one cornerstone of the "Object Oriented Programming" (OOP), whereas composition is a basic element used in "Procedural Programming". You can find more information about this when you search for Programming Paradigms. The term "pattern" in this context is entirely misplaced!


这篇关于类模式和对象模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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