学习面向对象的思维 [英] Learning object oriented thinking

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

问题描述

我目前正在使用C ++开发小型2D游戏引擎,但现在面临着一个守护进程-我很想设计一个切实可行的类系统".我的脑海中有一个障碍,使我无法查看应该在哪里使用类以及不应该在哪里使用类.我正在阅读有关引擎设计的文章,该文章旨在使用状态"类来管理不同游戏条目的状态(我使用的是int). 它还建议游戏的所有对象(不是io/video/sound等)都来自Renderable或NonRenderable类.太聪明了我已经知道那是一种明智的做法-我的意思是,Java中的每个对象都是基类对象,对吗?聪明,我知道!我怎么没有那样做呢?要真正进入这种心态,我需要阅读什么?

I'm currently working on a small 2D game-engine in C++, but I am now facing a daemon - I suck at designing a 'system of classes' that actually works. There are a blockade in my mind that disables me from seeing where I should use a class and where I should not. I was reading an article about engine-design and it purposed to use a 'State' class to manage the state of different game entries (I was using an int). It also suggested that all objects for the game (not io/video/sound etc) derive from either Renderable or NonRenderable classes. That's smart. I already know that that was a smart way of doing it - I mean, every object in Java is of baseclass Object right? Smart, I know that! How come I didn't do it that way? What do I have to read to really get into this mindset?

另一个例子.我正在用Ruby(非常简单)上这个暑期课程,我们应该设计一个露营地.简单的!因此,露营是样板"的集合,每个样板都有一个电表以测量客人消耗了多少电量.我的设计是三个类,一个用于露营-依次使用Guest和Plot类的数组.我的老师建议我多上课. WTF(!)是我的第一个想法,在哪里,上什么课?在我看来,一切都是一堂课-直到我意识到,也许仪表应该是一堂课?现在,量表是Plot类中的Integer.

Another example. I'm taking this summer-course in Ruby (really simple) and we're supposed to design a camping site. Simple! So, a camping is a collection of 'plots' that each have a electrical-gauge to measure how much power the guest has consumed. My design was three classes, one for a Camping - that in turn used arrays of Guest and Plot classes. My teacher suggested that I use more classes. WTF(!) was my first thought, where, what classes? Everything was a class in my opinion - until I realized, maybe the gauge should be a class to? Right now the gauge was an Integer in the Plot class.

我想学习如何针对我的问题提出面向对象的解决方案-而不仅仅是如何将最明显的东西放入类中!

I want to learn how to come up with a object oriented solutions to my problems - not just how to make the most obvious stuff into classes!

提示/书籍/文章/博客?

Tips/books/articles/blogs?

我已经获得CS的拼贴专业学位两年了,多年来一直作为业余爱好进行编程!我被卡住"了-这使我无法创建任何更大的软件!

I'm two years into a collage degree in CS and have been programming as a hobby for many years! I'm 'just' stuck - and it's preventing me from creating any larger piece of software!

推荐答案

我的个人经验是使用 面向对象的软件构造,第二版 ,作者:Bertrand Meyer.

My personal experience was learning Object Oriented Software Construction with Object Oriented Software Construction, 2nd Edition by Bertrand Meyer.

这本书对当时的我来说是无价的,并且仍然是我从中最全面地了解OO编程和软件构造的一本书.

The book was invaluable to me at that time, and still remains the single book from which I've learnt most regarding OO programming and software construction in general.

以下是它的一些优点:

  • A部分:问题中,这是对软件质量的很好定义.
  • B部分:面向对象的道路中,逻辑,分步地搜索OO技术,使读者认为调查是实时进行的,就像尚无已知结果.您可能会在此部分中找到所需的心态.
  • 在本书的技术核心 C部分:面向对象的技术中,您将使自己的知识扎实,并学习有关按合同,继承,泛型等设计的非常有用的技术.
  • li>
  • D部分:OO方法:很好地应用该方法是一种更实用的设计方法,我也发现它非常有用.例如,请参见如何查找类(22),您可以找到
  • In Part A: The issues, a very good definition of software quality.
  • In Part B: The road to object orientation, a logical, step by step search for OO techniques in a way that makes the reader think the investigation is being done live, that is, as if there were still no known results. You'll probably acquire the mindset you're looking for from this part.
  • In Part C: Object oriented techniques, the technical core of the book, you'll make your knowledge solid and learn very useful techniques regarding Design by Contract, Inheritance, Genericity, etc.
  • Part D: OO methodology: Applying the method well is a more practical approach on design, which I also find very useful. See for example How to find the classes (22), which you can find online.

这些部分之后,出现了更高级的主题,例如并发(30)数据库(31).

After these parts, more advanced topics come, such as Concurrency (30) or Databases (31).

由于这本书使用的是 Eiffel 语言(由作者设计),因此这将带给您正确的思维方式并进行教学你想.将这些思想应用于其他或多或少的面向对象编程语言将很容易.

Since the book uses the Eiffel language (designed by the author), this will put you in the right mindset and teach you to think. It will be easy to apply these ideas to other, more or less OO, programming languages.

这篇关于学习面向对象的思维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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