How to practice object oriented programming? [closed]

I’ve always programmed in procedural languages and currently I’m moving towards object orientation. The main problem I’ve faced is that I can’t see a way to practice object orientation in an effective way. I’ll explain my point. When I’ve learned PHP and C it was pretty easy to practice: it was just matter of choosing something and thinking about an algorithm for that thing.

In PHP for example, it was matter os sitting down and thinking: “well, just to practice, let me build one application with an administration area where people can add products”. This was pretty easy, it was matter of thinking of an algorithm to register some user, to login the user, and to add the products. Combining these with PHP features, it was a good way to practice.

Now, in object orientation we have lots of additional things. It’s not just a matter of thinking about an algorithm, but analysing requirements deeper, writing use cases, figuring out class diagrams, properties and methods, setting up dependency injection and lots of things.

The main point is that in the way I’ve been learning object orientation it seems that a good design is crucial, while in procedural languages one vague idea was enough. I’m not saying that in procedural languages we can write good software without design, just that for sake of practicing it is feasible, while in object orientation it seems not feasible to go without a good design, even for practicing.

This seems to be a problem, because if each time I’m going to practice I need to figure out tons of requirements, use cases and so on, it seems to become not a good way to become better at object orientation, because this requires me to have one whole idea for an app everytime I’m going to practice.

Because of that, what’s a good way to practice object orientation?

4

Now, in object orientation we have lots of additional things.

No you don’t…

It’s not just a matter of thinking about an algorithm, but analysing requirements deeper, writing use cases, figuring out class diagrams, properties and methods, setting up dependency injection and lots of things.

None of those things are necessary for practicing object oriented programming.

This was pretty easy, it was matter of thinking of an algorithm to register some user, to login the user, and to add the products.

All object oriented programming is instead of thinking of the algorithms to do these steps, you think about what objects are needed to do these steps – what functionality you want, what state is needed to do that, and what sort of interface you want to expose to the user. Just like you have to do in procedural programming.

The only difference is that instead of focusing on the functions you need and how they work, you focus on how the functionality and state is grouped into responsibilities, and how those responsibilities interact.

How to practice? The same way you practice procedural programming: pick a problem and solve the problem using bundles of classes. Figure out how that sucked, repeat with lessons learned.

2

Good question. Of course, what you are saying is that practicing OOP actually means practicing all of these things (requirements analysis, use cases, design patterns, etc.), which is true and may seem daunting at first.

My advice would be start your practice sessions by keeping two things in mind: test-driven development and the single responsibility principle.

Then just start off like you did with PHP/C: come up with an idea, think about what you need for that and implement these things one after the other. However, keep in mind, that you need to start from the tests (which forces you to define proper interfaces, as otherwise testability immediately suffers) and that TDD implies a red-green-refactor cycle. In other words, you have a tiny little bit of functionality, and once it’s working you refactor to get a proper OO-design if you didn’t make it from the start (which you won’t).

When doing this refactoring step always remind yourself of the SRP. If you added a second responsibility to your object it’s time to create something new.

When you develop like this, you need to be aware that your final solution will be far different from what you start with. Your learning curve will also be rather steep. For example, you will not learn what a Factory pattern is, but instead you will recognize the need for something that creates instances of your class in different ways. So if you haven’t heard of object-oriented design patterns at all, it’s good to read up a bit on those in parallel.

1

If you’re just starting in OOP, you can amuse yourself and “practice” offline by looking at just about any real-world system and considering what the objects are and what the relation between them is and what methods/interfaces they might support and how you’d represent them in a class hierarchy and as a collection of instantiated objects and what the object ownership relations would be and so on (note: I don’t mention the word “algorithms” in the above at all). Draw lots of diagrams (learn a bit of UML or similar) before you think about coding anything.

This will help you develop a much better sense of IS-A and HAS-A relations, which is probably the single most important classification in any OOP design (and despite that, it still seems to be something which many seasoned OOP language programmers struggle with). If you master IS-A/HAS-A there’s also IS-IMPLEMENTED-IN-TERMS-OF (which I’ve also seen described as IS-KIND-OF-A :^)

Seriously, next trip to the supermarket, just imagine someone has given you the job of writing a OOP simulation of the place…

2

What I remember from my C times (far far back in the past), we used to separate functions and procedures to different files based on their responsibility. I am not claiming that is perfect or anything, but it was a good starting point for when I actually started to program in object oriented languages.
So maybe, you could start with converting files to objects.

As far as OOP goes, it is really all about practice and striving for improvement. Rarely anyone gets it right from the ground up. Thus, iterations happen throughout project’s life-cycle.

Let’s add some terminology, object-oriented analysis and object-oriented design, as Peter Coad did in the 1990’s.

Together these form a software engineering discipline OOAD that can (done right) support the programmer at the point of writing and testing code. Object-oriented programming can then have its proper level of granularity, skillful use of programming language features to meet the functional objectives and design requirements specified at a project level.

Sometimes it’s a one-person project, and then you must wear all the hats (but not necessarily all at the same time). I’m a huge fan of test-driven development for my own personal projects (see Frank’s recommendation), but it doesn’t pertain only to object-oriented software development.

In a team project having a good division of responsibilities is a key to successful implementation. Skillful use of object-oriented design patterns helps team understanding by limiting the visible interfaces needed for analysis, data-feeds, and business logic to share a usable framework.

“well, just to practice, let me build one application with an administration area where people can add products”. This was pretty easy, it was matter of thinking of an algorithm to register some user, to login the user, and to add the products.

Why not do the same thing only this time with user objects and product objects? Also if you are using a language that supports both procedural and OO then you could try to implement objects based on the procedural standard library, like a file object.

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