SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 51

Thread: Do you do OOP?

  1. #26
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    Take a look at Zend Framework, I've been using it for months now and it has increased my productivity dramatically
    Really? Whenever I try the ZF for anything more than a simple project my productivity plummets dramatically

  2. #27
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    zend framework is how you should not program OOP.

    Its just a bunch a static classes that cause spaghetti code.

  3. #28
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    693
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by blueyon View Post
    zend framework is how you should not program OOP.

    Its just a bunch a static classes that cause spaghetti code.
    I just love the smell of FUD in the morning.

    Exactly how many "static classes" have you found in the framework? Zend_Debug is one. Is one too many for you?

  4. #29
    SitePoint Addict Mastodont's Avatar
    Join Date
    Mar 2007
    Location
    Czech Republic
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ahundiak View Post
    Exactly how many "static classes" have you found in the framework? Zend_Debug is one. Is one too many for you?
    Try to look for "static function" ... there you'll find entirely different count.

  5. #30
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    693
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Mastodont View Post
    Try to look for "static function" ... there you'll find entirely different count.
    How many? And what percentage of the total methods are static? And hows does that percentage compare with other popular frameworks? Hard data please.

    The original design from several years ago did indeed rely too much on static classes and methods. Most of those have since been re-factored. There are still a few but not many.

    There are some things wrong with the framework (which is true for all frame works) but overuse of static's is not one of them.

  6. #31
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by blueyon View Post
    Its just a bunch a static classes that cause spaghetti code.
    During the early builds and beta releases, that was true. However, that is certainly not the case anymore, and hasn't been since about beta 0.8. Zend Framework is now at 1.9.

    I suggest you take another look at Zend Framework before spreading rumors like that.

  7. #32
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't need to look at it again. It has 1,000's of people working on it and no proper direction.

    Its the too many cooks proverb.

    I don't even think many of the people who have been working on the zend framework have even been to college. They seem to be all self taught and have never worked with any other type of OOP language before.

    I'm sure that if the zend framework did not have the zend name on it then it would not be mentioned so much.

    I seem to remember the original creator of PHP Rasmus Lerdorf not being happy with zend framework.

    When people argue for using ZF its hard to tell what experiance they have, if they are just into the hype or which other frameworks they have used.

    Seriously what can ZF do that code igniter can not?

  8. #33
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    There are almost certainly a lot of static of methods in ZF, but to be fair, they are there to implement tried, tested and well researched architectural design patterns.

    I don't use Zend, much to my disadvantage I might add, but lets understand why those static methods are there before attempting to slate them...
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #34
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried, tested and well researched architectural design patterns

    So does every other OOP framework.

    patterns should only be used when there is a problem the pattern can solve. zend seems to use patterns when they are not needed. same with a lot of people on this forum. they don't use KISS. they just use patterns for the sake of using them.

    so what are you saying code igniter does not use design patterns? or any of the other frameworks.

  10. #35
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    693
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by blueyon View Post
    tried, tested and well researched architectural design patterns

    So does every other OOP framework.

    patterns should only be used when there is a problem the pattern can solve. zend seems to use patterns when they are not needed. same with a lot of people on this forum. they don't use KISS. they just use patterns for the sake of using them.

    so what are you saying code igniter does not use design patterns? or any of the other frameworks.
    It seems to me that you are digressing a bit. Once again, how many static classes are there in the framework and how does that compare to other frameworks? Let's be specific here otherwise the impression is given that maybe the code has not actually been looked at since it was released.

  11. #36
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hold on I just downloaded the latest version opened a random library file. all session methods are static and the same goes for the cache. first 2 files I open.

    that is not how you setup a session class or a cache class. how the hell are you soposed to draw a diagram showing where the cache or session is being used. Its completly stupied. they might aswell just use functions.

  12. #37
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    693
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by blueyon View Post
    hold on I just downloaded the latest version opened a random library file. all session methods are static and the same goes for the cache. first 2 files I open.

    that is not how you setup a session class or a cache class. how the hell are you soposed to draw a diagram showing where the cache or session is being used. Its completly stupied. they might aswell just use functions.
    Let me start by saying that it is very encouraging that you are willing to actually look at the code. It would have been nice if you had learned something about it before proclaiming it to be useless but I know how unreasonable that would be.

    Now you might want to take a peak at the documentation
    http://files.zend.com/help/Zend-Fram...-framework.htm

    Before getting all worked up. You see, Zend_Session_Namespace is the usual session object. Zend_Session is merely used to setup some parameters.

    Zend_Cache is similar.

    Once you start coding non-trivial apps you might start to understand how some thing work.

  13. #38
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    last version i used was ZendFramework-1.5.1

  14. #39
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look I'll show you how bad ZF is.

    No. Of Files

    Mail
    ZF: 29
    Code Ignter: 1

    Cache
    ZF: 16
    Code Ignter: 1

    Request
    ZF: 1
    Code Ignter: 1

    Log
    ZF: 14
    Code Ignter: 1

    Config
    ZF: 4
    Code Ignter: 1

    Controller
    ZF: 40
    Code Ignter: 1

    View
    ZF: 43
    Code Ignter: 1


    Ever heard that its harder to keep programming simple than it is writing complex code?

    This is because people with with years of experience such as myself know how to code efficiently with the minimum amount of code.

    I don't need ZF cache class I can code my own in 5 minutes with just the right number of needed methods and without the bloat of having to load more than 1 class.

    I just don't understand how you can argue when I show you these types of figures.

    One person just argued that ZF uses design patterns.
    So do all the other frameworks.

    What are you going to say next? that ZF is light weight?
    It clearly is not.

    That it uses MVC?
    So do a lot of the other frameworks and they do it the right way with a lot less classes.

    Are you going to say that ZF is easier to use?
    How can it be easier to use when it has such a large API? Its like learning smarty to create a web site instead of learning PHP.

    Its the fastest!
    I seem to remember ZF benchmarked against other frameworks and it got the lowset score. So its not a fast framework.

    Remember Zend the company did not create PHP they just piggy backed on it so they could sell their warez. They have about 6 contributors to PHP out of 1,000 people who are working on each release.

    Do you or anyone else have another argument why ZF is the best framework to use?

  15. #40
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Zend could maybe be taken to another topic? The OP:

    Do you?

    If you do, what are the steps you take from design to actual production?

    I'm a lonely programmer and I keep repeating codes. Haven't realized the power of OOP yet cause I don't know how to start. Don't know what are the classes I need. Don't know how to design classes that could be used in other projects.
    I think it's helpful to discuss what makes a good or bad class without getting too bogged down with Zend.

  16. #41
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by resting View Post
    I'm a lonely programmer and I keep repeating codes.
    Could you post a couple of (near) duplicates? I can comment on these. It's easier on a forum to deal with concrete problems first. makes it easier to establish a shared understanding before going on to the abstract stuff.

    Quote Originally Posted by resting View Post
    Haven't realized the power of OOP yet cause I don't know how to start.
    Give me an example of a problem you have right now.

    Quote Originally Posted by resting View Post
    Don't know what are the classes I need.
    I can't give you a general answer to this as it depends very much on the problem. I can give you some mechanics to deduce this yourself. Firstly I need a problem .

    Quote Originally Posted by resting View Post
    Don't know how to design classes that could be used in other projects.
    This is the kiss of death. Whatever you do, don't try to design for projects that don't exist yet.

    On the other hand, if you already have multiple projects then the process is easy. Write one, then start writing the other. Pull out common code and then plug the common code back in using a "flex point". Adding flex points is something that OO is extremely good at, and well, that's kind of the whole point. Even fiendishly difficult situations have known solutions (called "design patterns").

    Anyways, that's for the future. Right now you have a specific problem, yes?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  17. #42
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    UK
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Marcus

    another lonely programmer here, trying to get my classes organised and I have a real example.

    I'm rewriting a procedural ecommerce site to use oop. On the home page i want to display promotions - a PromoPanel for each promotion, and within that an ItemPanel for each product. The item panels can be fullwidth (uses class ItemPanel1) or 2 across (ItemPanel2). The display panels are already classes, but the data handling is all procedural.

    Tables used are:
    promotions : id, start&end date, title, layout (1 or 2 - to determine which itempanel to use), and a few other styling fields

    promoprodidx : promotionid, productid

    What i am doing at the moment is:
    query current promotions -> promoarray
    foreach promoarray,
    create PromoPanel
    query product details from promoprodidx & product table -> productarray
    pass productarray to PromoPanel
    within PromoPanel, use a switch to determine layout & foreach productarray create ItemPanel1 or ItemPanel2

    Would love some advice on how to tidy this all up!

  18. #43
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    www.cakephp.org worked for me.

  19. #44
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by treacle0996 View Post
    Would love some advice on how to tidy this all up!
    That's quite a lot of stuff .

    As this type of operation is often repeated for most web sites, what you are asking me for is the design of a web framework. There are lot's of ways of doing this:

    1) Use a full stack MVC framework such as Symphony or Cake. There are plenty to choose from.

    2) Roll your own from pieces, such as Zend controllers, ezComponents, Doctrine ORM, etc, etc.

    3) Write some parts of this yourself, using a few libraries.

    The essential division is the separation of the DB stuff from the page oriented stuff. What's left should be the minimum of glue code. It's the glue code that gets messy and is difficult to test. It's also the glue code that captures the design of the app, so you want it uncluttered.

    For the data we choose an ORM. You want to be able to write code like this...
    PHP Code:
    foreach ($products->promotions() as $promotion) {
        
    $layout_class $promotion->layout == 'wide' 'FullWidth' 'TwoColumn';
        foreach (
    $promotion->items as $item) {
            
    $layout = new $layout_class($item);
            ...
        }

    Probably not quite like this as this code would be spread over the pieces that paint the HTML, but this shows the interface to the data.

    $products is a "Repository" of data stuff. It holds the database connection and a single instance is created by the glue code. That should be the only database object that the glue code creates directly.

    $products->promotions() is probably something like a result set iterator, but one that wraps the row in a Promotion class as it returns each one.

    $promotion->layout is just a field in the $promotion.

    $promotion->items will trigger a method call to fetch the items from the database. Again, each row will be wrapped in a PromotionItem class.

    ORM (object relational mappers) do all of this for you. Checkout Doctrine and Propel, and most frameworks use these or have their own. The pattern is called "Active Record". There are simpler solutions for purely tabular data, but when you want lots of little UI objects it's a great pattern.

    I wouldn't write this stuff yourself unless you have a masochistic streak. It will take weeks to get both transactions and performance working together. Also most ORM tools include many optimisations. For example, instead of sending one query for the promotions and then a query for each item, most ORMs will send just one query for all of the subparts. That is two queries overall.

    On the front end you can write code like this...
    PHP Code:
    <?php
    ...
    $page = new MyPageController();
    ?>
    <html>
    <head><title><?= $page->title ?></title></head>
    ...
    That is, page oriented code. Dead easy and a natural choice if you are rolling your own.

    Or you can route everything through index.php and have one controller, called the "Front Controller" do all the routing. Most frameworks are FrontController based, but there is a learning curve associated with this and you can't mix and match different systems.

    Once all that mechanical stuff is separated out, it's easier to write your application. That goes into the controller for now. I'm simplifying here, as often you have an additional layer between the controller and the ORM. Sometimes this is explicitly called the "Model" or "Business Logic". Worry about that later.

    The best way to study front end patterns is to use a framework for a bit. The ORM stuff is best learned by trying to write a simple one in your spare time.

    I'm not sure this is the answer you want, but it's difficult to go into more detail without writing a few hundred lines of code. If you ask a follow on question, we can dig deeper.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  20. #45
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm..its kinda hard to explain a problem sometimes.
    But generally, i find myself copy and pasting codes and modifying a few inputs. i generally find this faster than thinking of how to build a flexible class. in the end, i end up with a large chunk of codes which i have to change if 1 changes, which is extremely frustrating cause they may span across many files.

    I do have problems remembering file names and variables that I created, any suggestions on that?

    head first OOA&D did a great explanation for me. however, i think its easier to refactor codes into OO rather than do it the first time? Is this the right approach? Or do you guys, do a whole lot of UML like use cases, class diagrams, sequence diagrams etc before coding?

    Another thing, when they say build codes that are reusable. Does it refer to the current project, or does it refer to other projects that may use it?

  21. #46
    SitePoint Evangelist
    Join Date
    Aug 2005
    Location
    Winnipeg
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    zend framework is how you should not program OOP.

    Its just a bunch a static classes that cause spaghetti code.
    I don't know about spaghetti but statics are not evil, their abuse is. Likewise for singletons, if you used singletons to limit the instances of a class to one, because anymore would cause issues and you did this in say a single cetralize location, than singletons make a lot of sense and thus so do statics.

    If you abuse singleton by calling it's static Class::getInstance() all over your code because you need it's object and are to lazy to inject the registry or whatever instead, then singletons suddenly become bad practice.

    Zend IMHO has the greatest focus on IoC than any other framework or codebase, so statics or not, it's by far the most flexible to use as a library.

    It's bloated, over engineered implementation can at times bug me, but I'd rather that than concrete implementations like that of CodeIgnitor, etc.

    Cheers,
    Alex
    The only constant in software is change itself

  22. #47
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    UK
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that marcus. I understand the theory, just need to do a lot more reading now. I don't really understand some of the terminology.

    Was going to post a request for a good book to explain it all and noticed the link in your signature. PHP in action sounds like it was written for me!. My only concern is that it's 2 years old. Presumably, things haven't changed too much? same concepts, right?

    Unfortunately, too late for the ' don't write it all yourself' warning - have spent weeks and weeks on the site so far.

    Thanks again for your time.

  23. #48
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I was never able to code an application of any measurable complexity until I started using OOP, why? Simple, because without, I found I needed to be aware of all things, all the time.

    With OOP, I just need to code small to build big. Small methods, in small objects in small modules and so forth...
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  24. #49
    @russellg RussellG's Avatar
    Join Date
    Jun 2000
    Location
    Gold Coast, Queensland
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    I know this is an old thread but I think it's worth bumping.

    I was going to learn PHP just using functions but I've decided to learn it the OOP way so I don't end up having to teach myself all over again.

    I have currently been teaching myself the following way:

    - Read books/articles about general OOP theory.
    - Read books/articles on PHP specific OOP.
    - Checking out different frameworks written in PHP (currently reading about Yii and I really like how it all works).
    - Writing code I see in different books/articles. I find that writing it out and not just reading about it helps my understanding somehow.
    - Starting to write some basic classes and hesitantly working on a mysql db connection script that also outputs and a form validation script.
    - Taking a break doing some xhtml/css and reading a good penguin classic

    It's a bit of a process, however I've found it infinitely rewarding

  25. #50
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used c++, c# and Java before PHP. You should start with basic oo concepts and after that you should read and understand design patterns. If you don't know and understand design patterns you can not say you really write oo code.


Bookmarks

Posting Permissions

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