Learning good OOP design and unlearning some bad habits [duplicate]

Possible Duplicate:
What books or resources would you recommend to learn practical OO design and development concepts?

I have been mostly a C programmer so far in my career with knowledge of C++. I rely on C++ mostly for the convenience STL provides and I hardly ever focus on good design practices. As I have started to look for a new job position, this bad habit of mine has come back to haunt me. During the interviews, I have been asked to design a problem (like chess, or some other scenario) using OOP and I doing really badly at that (I came to know this through feedback from one interview).

I tried to google stuff and came up with so many opinions and related books that I don’t know where to begin. I need a good through introduction to OOP design with which I can learn practical design, not just theory.

Can you point me to any book which meets my requirements? I prefer C++, but any other language is fine as long as I can pick-up good practices.

Also, I know that books can only go so far. I would also appreciate any good practice project ideas that helped you learn and improve your OOP concepts.

5

As for training, I suggest going to http://www.cleancoders.com/ and watching those. They cover very important ideas.

Once you have watched the videos, take a look at Head First Design Patterns. That walks you through a number of problems and solutions.

I don’t have specific project suggestions, but I would advise you to try whatever project in a strictly object oriented language such as Java. C++ let’s you cheat too easily, and maybe without even knowing you are doing so.

2

(IMO) There are not great books about software design. Many of the patterns books (I prefer the original, but have heard good things about some others) are pretty good to get the terminology and firm up concepts, but they should be used only after some practice. Without the practice first, programmers tend to over-apply design patterns or misunderstand what problems the patterns prevent.

As for practice problems, I recommend something you’ve already done for a start. Then you understand the domain and what it’s supposed to do and can focus on design alone. Mostly though you just need to iterate. Design a program, implement it, see how it works (and doesn’t). Make a new design with lessons learned for a new problem, repeat.

Program design is one of those things that ends up being more craft than science. Keep at it and you’ll get progressively better.

The ‘Head First Design Patterns’ book mentioned in the Ben’s answer is excellent. It really brings the ideas from the original ‘Gang of Four’ Design Patterns Book to life.

As Telastyn says in the answer, understanding to domain is critical and this will really help inform your object model. For this I really recommend Eric Evans’ Domain Driven Design. It also has a great bibliography of books on OO.

Finally, your approach to testing will inform the way you design your software and what OO patterns you use.

I didn’t really ‘get’ Factory Pattern until I had to write a unit test for some legacy code which in its constructor created one of its dependencies.

This made it very hard to test and drove me to refactor the code to have the dependency created by a Factory which when the tests were being run could be set up to return a mock object.

A great book on the subject is Object Oriented Design Heuristics. The book has over 60 heuristics in it which are language independent. In addition to the theory the book has a 122 page appendix of C++ examples. I can’t recommend this book enough, it is an excellent introduction.

It’s a bit more difficult of a read, but Applying UML And Patterns is also a great introduction. This book is huge and is not a quick read, but it uses two case studies to introduce the material (the monopoly game and a point of sale system).

These two books (and Refactoring) are 3 of the biggest influences in my programming career. You won’t be disappointed.

1

I think Uncle Bob’s Agile Principles, Patterns, and Practices would be a really good book for you. The book uses C# for many examples but think of those examples as pseudo-code rather than production C#. Everything that book teaches can easily be applied to just about any OO language and the level of material will probably be perfect for you.

While you are new and learning, I would strongly advise to stay away from “design patterns” books. Too many people pick those up, learn few patterns and start slapping them all over the place. As Uncle Bob points out in the above book, you should code into a pattern when you see one developing, rather than starting with the goal of building a specific pattern in the first place. However, you need good OOP sense before you can make design decision that would lead you to a pattern.

As far as material outside of the books, I would say learn the SOLID, KISS and DRY principles. And when I say “learn”, I don’t mean read about them and think you understand them. I mean, when you code you live and breath those principles. Every time you add another function or another variable keep asking yourself:

  • am I duplicating existing code?
  • Is my function/class doing too many things?
  • Can what I just wrote be done simpler?
  • ….

As @worldofchris mentioned (+1 to that answer), I would also recommend learning TDD while you are learning OO. The two go hand-in-hand and well-designed code, will lend itself to be easily testable. Conversely, if your code is already testable, it’s quality will tend to be higher in relation to code that has no unit test coverage.

  • Clean Code

  • Pragmatic Programmer

  • Working with Legacy Code

The majority of books will make you feel happy. That won’t get you a job.

Start by reading few chapters of Pragmatic Programmer and then move onto Clean Code. Review your old code as you read the books and start refactoring.

Reading books won’t give you experience, but making your code “clean” will. It’s up to you to decide when to draw the line regarding quality of your code.

Reason why I recommend these books is because guys who wrote them have been working in this industry for decades, and they have a very good idea of what works and what doesn’t.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật