良好的挑战/任务/练习来学习或提高面向对象编程(OOP)技能

提高您的面向对象编程技能的一个好的挑战是什么?

这个投票背后的想法是提供哪些练习对学习 OOP 有用的想法。

这个挑战应该是尽可能不需要语言的,只需要很少或根本不需要使用特定的库,或者只需要使用最常见的库。每个答案尽量只包括一个质疑,这样投票就只对应该质疑的优点。如果指出所需的技能水平,以及为什么这是一个有用的练习背后的理由,也会很好。

然后,挑战的解决方案可以作为“如何...”问题的答案发布,并从这里链接。

例如:

  • Challenge-实现后进先出堆栈
  • 技能水平-初学者
  • Rationale-提供如何引用对象的经验
76393 次浏览

Certainly a good challenge, although less accessible than a "start from scratch" assignment, is to refactor some existing code that either doesn't use inheritance or doesn't use very much of it to make greater use of inheritance. The process of refactoring will expose a lot of the benefits and gotchas of oop, as it certainly has for me on my most recent project. It also pushed me to understand the concepts better than past projects have where I've created my own object oriented designs.

Challenge: Write a wrapper for your web site/service API of choice in your language of choice, that doesn't already exist (ex. a ZenDesk API wrapper written in C#). Release the wrapper as open source for others to use.

Skill Level: Beginner to Intermediate

Rationale: To learn how to extrapolate a 3rd party web service API into a meaningful set of objects/classes, making the reuse of that API easier in your chosen language.

After you have learned the basics, study the "Gang of four" design patterns book.

http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1221488916&sr=8-1

This is a classic, and a must read for any coder who wants to understand how to use OO to design elegant solutions to common coding problems.

A given task has very little to do with being "OOP", it's more in how you grade it.

I would look at the Refactoring book, chapter 3, and make sure none of the bad code smells exist in the solution. Or, more importantly, go over ones that do apply.

Most importantly, watch for the existence of setters and getters (indicating that you are operating on values from a class and not asking the class to operate on it's own values)--or using "extends" without applying the Liskov Substitution Principle, stuff like that.

Take a procedural-style written piece of code and try to transform it into OOP based solution. During the process, consult a book on refactoring and design patterns. A friend of mine was able to make a huge step forward in understanding object oriented concepts exactly this way. As with anything, this might not work for everyone.

I have found CRC cards to be quite effective in learning, teaching and building good OO design.

Write a challenging program from scratch. Try to get some people (around five, that should be doable) to use it. Respond to their change requests.

Adapt your program's design. Start small, then watch it grow. Manage this growth. This is hard. You will also have to fix bugs and maintain the thing over time, which for me was a very valuable lesson.

Building Skills in Object-Oriented Design is a free book that might be of use.

The description is as follows:

"The intent of this book is to help the beginning designer by giving them a sequence of interesting and moderately complex exercises in OO design. This book can also help managers develop a level of comfort with the process of OO software development. The applications we will build are a step above trivial, and will require some careful thought and design. Further, because the applications are largely recreational in nature, they are interesting and engaging. This book allows the reader to explore the processes and artifacts of OO design before project deadlines make good design seem impossible."