0

I know about OOP and how to use it, however because of the way i use there is actually no need for it.

Say i have this

class MyClass { function myfunction() { echo 'text'; } } 

Well it isn't necessarily the same, but that is what i have in mind. Even though i use OOP, i am not using it right. What i mean is, that i don't need OOP there, and i wan't to learn to make it be needed.

3
  • Here is an optimized procedural version: <?php echo 'text'; ?> ha Commented Mar 4, 2011 at 1:01
  • Can you give us a more 'real world' example of where you used OOP but felt like you should have done it procedurally? For instance, displaying a random image on your home page vs building a publishing platform from scratch? Commented Mar 4, 2011 at 2:34
  • 1
    @ThomasHunter: allow me to optimize further: text Commented Mar 31, 2011 at 6:36

2 Answers 2

3

First of all you should determine if it is at all necessary to architecture your project following OOP principles. From my experience almost all projects complexer than a hitcounter could use some form of OOP.

But since you are having trouble understanding how to properly implement OOP principles in your project i'm inclined to think your problem isn't technical in nature but more organizational.

Do you have a clear view on your project or a written brief/spec? What components are there? What data entities? Are databases involved? Do you need to communicate with external webservices? Over soap or rest? Are your going the MVC way?

The answer to all these questions and alot more will make you think of your project from a higher point of view, from there on work down and you'll easily start seeing how you can implement OOP in your project.

It will take some practice and you will make mistakes and decisions you will regret later but that's all part of the learning process.

Do a search on SO for OOP books and you'll find a treasure of information on all things OOP. Clicketyclick: https://stackoverflow.com/search?q=object+oriented+programming+books

Sign up to request clarification or add additional context in comments.

Comments

1

The problem here is with "and i want to learn to make it be needed."

I don't think that this is possible to learn. All you need to know (and you seem to have some understanding of it already) is when it is appropriate to use. If all you need to do is echo some text, there is no way to make it necessary to apply the OO paradigm.

2 Comments

I am going to make some software written in PHP and i want to use OOP, however i want to be certain that the way i will be using it, it will actually be needed.
If you want to practice using OOP, you should choose a project that it's suited for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.