Class Advantages

Discussion in 'PHP' started by FishSword, Nov 30, 2010.

  1. #1
    Hiya,

    I'm still hesitant on starting my project, as I am unsure whether or not to code everything using classes or not. Whilst searching the net for inspiration, I came across this script on Code Canyon.

    Does this script have to be coded in a class, or can the same results be achieved by simply using functions. What would be the main advantage(s) for coding such a script using classes?

    This is still something I have difficulty getting my head around.
    I would appreciate any body's thoughts on this topic.

    Thanks,
    FishSword
     
    FishSword, Nov 30, 2010 IP
  2. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    A pagination script doesnt have to be written using a class, the author of this particular one chose to take that approach. Writing as a class helps organize code , grouping functions that serve a common purpose together.
     
    fr33lanc3, Nov 30, 2010 IP
  3. FishSword

    FishSword Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thanks for your reply! ;)
    Do classes not offer any other advantages, besides just code organisation?
     
    FishSword, Nov 30, 2010 IP
  4. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Its easy to maintain, flexible, you can write less code once a class is written by extending the core class...

    At first it takes a bit of work to grasp the concept, but once you understand you see the benefit.
     
    fr33lanc3, Nov 30, 2010 IP
  5. FishSword

    FishSword Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    Thanks once again! ;)
    Do classes have any disadvantages? - e.g. Do they put a lot more strain on the server?
     
    FishSword, Nov 30, 2010 IP
  6. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Any code can be written poorly and cause server problems. If you are going to write a larger application, using classes may be a good way to go. For writing something as simple as a pagination script, it could be overkill. (not in the sense of server strain, but just may not need to implement a class to accomplish the function). With coding, there are always many ways to accomplish an end result. Budgets, deadlines, long term goals of project... all have a deciding factor on the approach to take.
     
    fr33lanc3, Nov 30, 2010 IP
  7. mephisto73

    mephisto73 Greenhorn

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    To summarize, classes are not a requirement to write even large projects, but they might help maintainability, organization and also save some coding work.

    Most quick projects I do I complete using ordinary functions, and it works fine for me.
     
    mephisto73, Dec 1, 2010 IP