Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    236
    Thanks
    11
    Thanked 5 Times in 5 Posts

    When to use OOP?

    Hi guys.

    I am learning OOP with its classes, instances, methods etc etc.

    As i am only learning it through the internet and not in a classroom i am looking at it and reading it, all looks pretty simple within reason.

    But i am looking at some examples and i am thinking it would be easier just to do if,else, switch and loops rather than some of these examples.

    I know that the lessons and tutorials are made to be very simple so that people can understand them which is great.

    But with me its not the understanding how they work and why a static :: should be used etc etc.

    Mine is knowing when to use OOP and when not to over complicate things.

    Can anyone give me an example of when to start using OOP when coding.

    Thanks

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    If you can do everything you need without OOP, do so. If you reach the point where something would be easier to implement using OOP, use it. That's the way I'd go. It has its uses, but it is more code for none to little gain if you don't specifically need it.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I'll half agree with the above.
    OOP is always more work and more code than it would take to do the same task procedurally. This is the nature of OOP.
    However, I won't agree with little to no gain. OOP provides you with many benefits including extreme reusability, centralized control, and dynamic handling with polymorphism. These can all be done in procedural as well, but to simulate the polymorphism in particular would take a lot of procedural code to do so.
    So my approach is more of a short term pain for long term gain approach. If you have an extensive library of classes available to you, each project takes less and less custom code to build it. This becomes especially true when dealing with design patterns which you come to know (and love) when developing. The only thing to remember in OOP is that an interface is your best friend.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by Fou-Lu View Post
    I'll half agree with the above.
    OOP is always more work and more code than it would take to do the same task procedurally. This is the nature of OOP.
    However, I won't agree with little to no gain. OOP provides you with many benefits including extreme reusability, centralized control, and dynamic handling with polymorphism. These can all be done in procedural as well, but to simulate the polymorphism in particular would take a lot of procedural code to do so.
    So my approach is more of a short term pain for long term gain approach. If you have an extensive library of classes available to you, each project takes less and less custom code to build it. This becomes especially true when dealing with design patterns which you come to know (and love) when developing. The only thing to remember in OOP is that an interface is your best friend.
    I mostly agree with this but I would like to add to it. If your only exposure to OOP is in web development you might not really see the benefit and the full potential of OOP. I wouldn't say OOP always takes more work than procedural code though, since as you said to replicate some of the advanced OOP features would take a lot of procedural code.
    OracleGuy

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by oracleguy View Post
    I mostly agree with this but I would like to add to it. If your only exposure to OOP is in web development you might not really see the benefit and the full potential of OOP. I wouldn't say OOP always takes more work than procedural code though, since as you said to replicate some of the advanced OOP features would take a lot of procedural code.
    Oooh yeah that's a good point. I personally see great potential in OOP with web environments now, but I had not until I learned OOP outside of a web environment.

  • #6
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But with me its not the understanding how they work and why a static :: should be used etc etc.
    I think, it will be good for you when you read some literatur about the different design patterns. so you can learn for example why and when a static function can be usefull...


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •