15

I have been working on some of the projects of my own and dont have any indrustial exposure. Currently i use simple approach for developing small applications with negligible OO approach like creating a common class for database functions using polymorphism of functions little bit use of constructors but i dont really able to think of how to implement whole project logic using OOP.

I know what are interface, abstract class, sealed classes and other oops concepts and very much clear picture in mind. But problem is that when and how should i implement OOP heavily where I should.

Do i need to study real time applications and their case studies, if so please refer me some sites or books/e-books from where i can read them and can be able to implement them.

Currently i feel myself incomplete while programming. I implement database and most of its components effeciently, but a kid while trying to use OOP.

I have read many examples that tries to make one understand OOP like shape eg, car eg. all these kind of. They r gud to clear concepts but not enough to implement in some live project

Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286
  • 7
    Can someone explain to me where theterm "OOPS" that keeps on cropping up here comes from? I've been using OO languages for well over 20 years and have never come across it before. –  Dec 24 '09 at 18:31
  • 3
    Voted up, this is a great example of a new programmer question. Many programmers run into these problems when just starting out, real world experience plays a big part in knowing just how and when to implement OO concepts. – Chris Kannon Dec 24 '09 at 18:32
  • Neil, Object Oriented Programming & Systems.. I'm not sure where it originated, and I've never used the term.. – Chris Kannon Dec 24 '09 at 18:35
  • 1
    I also voted it up (to cancel the downvote) , but I don't think it is such a great SO question, as the answer is really to read some books and to gain some real world experience. –  Dec 24 '09 at 18:36
  • That's true Neal, but as long as there are fresh developers someone will need to keep telling them that experience really counts :) – flesh Dec 24 '09 at 18:39
  • thx @Neil Butterworth for voting up but I posted this question bcoz i have read many books, I dont know whether they r up to the mark. I know this much only that I m crazy for programming and always remains hungry to learn more and more. – Shantanu Gupta Dec 24 '09 at 18:40

6 Answers6

16

The first step in learning to apply OOP is to gather common funcitonality and data into classes. You will not do a great job at first, but you will get better. A recent article in Code Magazine about getting back to basics expresses this well.

Start attempting to make (classes that will become) real objects that represent real things in your solution. (There a fancy name for this, but it's also very basic.) This is NOT making utility classes of handy, thematically related functions. Try to arrange things so that the data maintained in your objects saves you parameters when calling methods on that object. Think of the objects that will exists as real individual things in a community. Personify them. Arrange things so that you're not worried about what's going on in the classes while you're using their functionality.

I would not worry about all these design patterns at first. Better to first practice the basic OOP concepts that you have learned. Focusing on these patterns causes a lot of people to skip really thinking about the philosophy of OOP and instead try to jam their situation into a pre-packaged plan. Read about "design patterns" for entertainment and ideas. Later, you'll want to really study them and attempt to specifically implement some of them.

In short, you have to jump in and start applying what you have learned. You need to make some poor designs before you make some good ones, so don't worry about it.

Edit in response to comment from questioner: I think the next step might be to concentrate on the relationships between your classes. Once you are using a Customer object in your logic, for example, you should have to spend No Effort getting the related Order object. Make a property oCustomer.Orders, that returns List<Order>. (This is a c# example.) In this property get all that customer's orders, put them in list object, maintain it in a private variable in case the property is called again, and return that list object. If you have already done this, look for the next hardest new thing to try. Perhaps you need to often find the date a customer first made an order. Then, create an Orders class that inherits from Collection<order> to replace your basic List<order>, and add the property FirstOrder. You can then do var FirstOrderDate = oCustomer.Orders.FirstOrder.OrderDate.

Keep trying to do the next hardest new thing. Inherit and add members. Make a base class with child classes. Override base class members. Use and get good with custom collections.

Learn from the object models you are using. When you see something intuitive and easy to use, do like that! Early in my career I had to extensively use the MS-word object model, which was intuitive and easy. When I made my own libraries, I tried to duplicate that feel; the results were good.

Eventually study the patterns. As much as I advise that you not be over-awed by them, they are a great source of ideas and most importantly stuff to try out. (Knowing the names of common "patterns" is good for communication purposes also.) For example, when you see the plug-in model, the concept of interfaces will really make sense.

Patrick Karcher
  • 22,995
  • 5
  • 52
  • 66
  • @Patrick Karcher thx a lot for such a helpful advice. I smiled on ur answer thinking of my situation as I have started following your steps from 1 year back and now at present i have a complete database communication class with little bit of polymorphism and constructors implemented in tat. Which means i m already following 1st 2 paragraph of ur suggestions. Remaining two r still a problem for me. Can u plz guide me further about remaing 2 para's. I would have voted ur answer +10 if i could. thx anyway. Great help – Shantanu Gupta Dec 24 '09 at 18:50
  • 1
    Not worrying about design patterns often means re-inventing the wheel indefinitely. Often the best way to implement things and many of the pitfalls that are created in the process can be addressed without the headache and heartache involved. Design patterns aren't always the answer, but they usually apply themselves to it. – Chris Kannon Dec 24 '09 at 18:58
  • I dont know what "design patterns" actually are but it seems as if this answer deserves 200 out of 100. Xcelent answer from my personeal view. – Shantanu Gupta Dec 24 '09 at 18:59
  • 2
    you do eventually want to study some design patterns. Chris and I might not actually disagree that much about there importance. It's just that I often see someone forcefully implement a pattern they read, using basic OOP concepts and thinking. Which is bad. Design patterns as coolness/excuse/laziness/crutch is bad, design patterns as wisdom/education/good-idea/communication is good. Definately study design patterns. – Patrick Karcher Dec 24 '09 at 19:31
  • simply great great great answer. U r making me crazy to do all these step very fast. I will surely disturb u as soon as i learn up to this much that u suggested. Thx a lot lot lot. If there would have any option in stack for marking some 1 as ur teacher or something like that u would have been the first for me over here – Shantanu Gupta Dec 24 '09 at 19:37
  • Wow, thanks! I'm glad I was able to address what you needed. Good luck! – Patrick Karcher Dec 24 '09 at 19:51
  • 2
    Totally agree on getting to design patterns, but in due time. In my experience, it is not obvious why certain patterns are good unless you have some practical sense of what works and doesn't with "naive" OO, and designing an application in general. Start writing OO code without worrying about patterns, try to figure out recurring issues or challenges, and then look into patterns. – Mathias Dec 24 '09 at 20:08
  • @Patrick and All: I feel great when using OO code. Now I have started implementing most of the OO concepts in my programming and do understands where should I use it. After a long time with support from all of you I have achieved some target that i fixed for myself. hurrey – Shantanu Gupta Jun 24 '10 at 10:34
  • @Shantanu: Fantastic. It's getting funner too I bet, right? – Patrick Karcher Mar 26 '11 at 20:11
  • @Patrick: Yes you are right...almost an year passed now and following suggestions of everyone, now I finds myself at place where i am more comfortable starting with OO implementation just bcoz i read many design patters although they were easy to understand from the starting but difficult to think where to implement them...but now after keep thinking and recalling design patters I finally started using some of them....I feels glad now when I uses any of the design patter. Now I have a good hand on playing with List. As it is still a start for me... – Shantanu Gupta Mar 28 '11 at 12:50
4

It is a hard problem this - good OO design only becomes second nature once you've got the experience of building real-world applications, having to change them, being forced to re-appraise your original designs and so on. The problem is compounded by most examples being utterly trivial.

The best thing I can suggest is if you search for implementations of design patterns. These won't always provide non banal/trivial examples, but it will help to recognise the application of OO principles when you see them in other peoples' software. The other thing you could do, is try to create a real implementation of a series of common patterns yourself. Then when you're writing a production application, hopefully you will be able to make the connection and apply the relevant pattern / principle / design technique.

In short, there's no subsititute for experience.

For real code, I'd start looking at some projects that interest you on somewhere like codeplex.

Here's the classic list of GOF design patterns.

Here's a few examples of common patterns:

flesh
  • 23,725
  • 24
  • 80
  • 97
  • the problem with me is that i m not getting any xposure about some industrial projects but i want to implement OOPS now. SO can u suggest me the best way i can do to do it of my on – Shantanu Gupta Dec 24 '09 at 18:31
  • 1
    +1. Read more code, read more books/articles, write more code, and generally keep learning. – TrueWill Dec 24 '09 at 18:37
  • thx flesh I would go for all the links and will try to implement OOP very soon, Now i want to play with OOPS as well. – Shantanu Gupta Dec 24 '09 at 18:44
3

First off, i'd just like to recommend you use OOP instead of OOPS. OOP is a programming paradigm so the 'System' part isn't really necessary (but of course this is only an opinion). Also, most people recognize OOP easier, so it'll make your question more understandable. Finally, because OOPS makes Object Oriented Programming look like a mistake (hehehe... sorry, bad joke). Of course, this is only my opinion, and i could be wrong of course.

Anyway, on to business. I think you are having problems because you are over-thinking at the start of your planning phase. Stop thinking about the methods and attributes each object has. Don't think about how it might be useful or how you are going to use it. Forget about the computer and how you are going to implement it. Just list whatever objects come to mind. You mentioned making a database application. You can start with what data you want to save. If you are going to make a database of students, for example, you would probably want to make a Student object. You would also need a way to connect to the database, so you would probably want an object to serve as a connection to the database. Of course, these two objects are just suggestions; it's up to you whether you wish to use them.

After making a long list of objects, start looking at the objects you've made and list down what they do. Just because an object doesn't do anything, doesn't mean you should remove it from the list. Take the 'Student' object, for example. This object may be composed of getters and setters, but it is a model of a student and would thus be extremely useful in a database system. If you know the C programming language, you can think of the 'Student' object as a struct. Once you finish this list, try and combine objects that seem really similar. Drop the objects that don't have anything to do, passively (like storing data) or actively (like connecting to the database, or getting user input). You should have your objects, and a majority of their attributes and methods. All that is left to do is implement these objects and add more to the functionality.

To further understand this, i recommend reading on Entity-Relationship Diagrams. That should help you in your design. Because i believe you are over-thinking things, i suggest not reading into patterns and GOF just yet, because it may just confuse you even more. It will serve you very well when you surpass this hindrance, but right now, it'll only add more layers to your problem.

cesar
  • 8,944
  • 12
  • 46
  • 59
  • +1 Again this post to bcomes very valuable to me. Here are some gud guides who r understanding what's going into the mind of newbie and how to resolve them. Thx now i started getting ideas how to think of oo structure. – Shantanu Gupta Dec 24 '09 at 19:43
1

I believe what you are looking for is Object Oriented Design Patterns. Often many of the best OOP principles are implemented in standard design patterns which can be used in many types of projects.

Many developers when looking at a problem will attempt to fit it into a standard design pattern, which when used correctly speeds development!

I'd suggest reading up on object oriented design patterns and how they can be applied. A good example of this is the use of Abstract classes or interfaces in the Factory method pattern.

Wikipedia (http://en.wikipedia.org/wiki/Factory_method_pattern)

Chris Kannon
  • 5,931
  • 4
  • 25
  • 35
1

At first I would recommend this classic book on design patterns. http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&s=books&qid=1261679601&sr=8-1

But in the end, all that really matters is working experience on big real-life projects! When you start working, and after a few years, everything will become much clearer.

Alex Ntousias
  • 8,962
  • 8
  • 39
  • 47
1

One moment when things clicked for me was reading "Test-Driven Development, by Example", by Kent Beck. The whole first part of the book is a walk-through of Beck designing a piece of functionality, step by step. I found it very helpful because you see the process happen in an organic way - starting with very few classes, which evolve over time.
I think starting with patterns is not necessarily a good idea. Design patterns are great, but I find that why they are useful becomes apparent only after having done it wrong on a real-life project first, and gained a sense for what works and what doesn't in OO.

Mathias
  • 15,191
  • 9
  • 60
  • 92