News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Qafoo Blog:
Utilize Dynamic Dispatch
October 16, 2014 @ 11:52:18

On the Qafoo blog today Tobias Schlitt talks about dynamic dispatch, what he calls a "fundamental concept of OOP" to help provide clean, clear interfaces in the code.

I want to use this blog post to illustrate the concept of dynamic dispatch which I use a lot recently to motivate creating clean OO structures in my trainings. In my experience, this helps people to understand why we want to write code in this way. After that I will show why traits are bad in this direction.

He explains the concept of "dynamic dispatch" by starting from the beginning...with procedural PHP code. He looks at the usual flow of this kind of application that call shared functions in a "top down" fashion. He looks at what would happen if new logging needs were introduced (use a new method? patch the current one?) and the dependencies that can be introduced because of it. With this in mind, he continues and talks about how the "dynamic dispatch" happens during the code execution, splitting the log request based on the information it's given instead of different implementations for each. He points out that using a trait doesn't allow for this abstraction and instead embeds the code into the class itself, re-introducing the original problem.

0 comments voice your opinion now!
dynamic dispatch oop concept example logger trait compare

Link: http://qafoo.com/blog/072_utilize_dynamic_dispatch.html

Mathias Verraes:
Objects as Contracts for Behaviour
September 29, 2014 @ 11:10:33

Mathias Verraes has a new post to his site today with an interesting idea when it comes to handling the architecture of an application: using objects as the contracts for behavior. He suggests that the objects themselves define how other pieces of code should interact with them, not necessarily external services. He illustrates with an invoice and appointment example.

Of course invoices do not pay themselves, but that's not what an object model is trying to do. An invoice exposes the behaviour of being able to be paid. That ability is in fact essential to what it means to be an invoice. The behaviour is an inherent property of an invoice. If an invoice doesn't have the ability of being paid, there's no point in issuing invoices at all. In other words, the contract of an invoice object declares that its interface includes payment as a feature. Its promise to the outside world is that it allows an outsider to pay for it. Encapsulation of state and behaviour is the core idea behind objects.

He wonders why, if this is more true to the "object-oriented programming" ideals, the idea of encapsulating procedural code as objects is so widespread. He suggests a lack of education on the subject or maybe even confusion from spoken languages themselves.

0 comments voice your opinion now!
objectoriented programming oop contract expose behavior property

Link: http://verraes.net/2014/09/objects-as-contracts-for-behaviour/

Reddit.com:
Which is a better way to learn PHP?
September 09, 2014 @ 15:54:59

In the /r/PHP community on Reddit there's a discussion going on about the best way to learn PHP. The op wonders:

Now a days there are numerous PHP Framework popping out and being fully supported, just to put it straight. Should i jump on one of those like CI, etc. and forget about doing a native code? I'm a new in PHP and now i'm confused which to choose.

There's lots of good answers to the questions with people leaning both ways. Suggestions include:

  • "The answer is that you should do both raw php programming as well as get familiar with frameworks. This might sound like a copout, but it's really not."
  • "I would agree with the others that it's best to learn the basics of PHP first. Understand PHP and its various constructs, particularly if you're a new programmer."
  • "PHP frameworks ARE PHP. [...] Regardless, frameworks are generally pretty advanced PHP, and may be hard to get into without a good grounding in PHP generally, and OOP specifically."
  • "Learn PHP. You might be able to make a site if all you do is focus on a particular framework, but by focusing on learning to use the language itself you'll be able to switch from one framework to another. "
  • "If you don't have at least some understanding of the basics, learning a framework to start off it a bit of overkill and may or may not actually help you much. I think it's hard to appreciate what a good framework does for you if you don't have a fair understanding of how things are often done without one."

Have some thoughts of your own? Check out the full post and share them!

0 comments voice your opinion now!
learn language framework oop opinion

Link: http://www.reddit.com/r/PHP/comments/2frwdy/which_is_a_better_way_to_learn_php/

SitePoint PHP Blog:
PHP Extension Development with PHP-CPP Object Oriented Code
April 08, 2014 @ 09:11:17

The SitePoint PHP blog has posted the second part of their look at the PHP-CPP tool and how to use it for developing PHP extensions. In this second part of the series Taylor Ren builds on what was learned in part one and talks more about the OOP features of the tool.

In this part, we further elaborate its OO features. We will mimic a complex number (in the form of 3+4i) class to demonstrate some more useful and powerful sides of the PHP-CPP library.

He walks you though a few changes to the environment files (the .ini configuration file and the Makefile) to set things up. He then gets into the C++/PHP constructor and getters and setters for private class variables, much like PHP's __get and __set. His example shows a set of methods that do some mathematical calculations including one to show the result in a "more friendly way". He includes the code for registering these functions and, finally, the steps to compile, install and test the extension.

0 comments voice your opinion now!
phpcpp extension development part2 series oop code

Link: http://www.sitepoint.com/php-extension-development-php-cpp-object-oriented-code

Voices of the ElePHPant:
Interview #2 with Larry Garfield Drupal 8 & Object Oriented Programming
March 12, 2014 @ 09:07:16

The Voices of the ElePHPant podcast has posted the second part of their interview with Larry Garfield (part one is here) talking about Drupal 8 and OOP.

Topics mentioned include the D8FTW blog post series, Refactor Chicago and the Chicago Advanced Drupal User Group.

You can listen to this latest episode either through the in-page player or by downloading the mp3 directly. You can also subscribe to their mailing list for this and more great shows.

0 comments voice your opinion now!
voicesoftheelephpant community interview larrygarfield drupal drupal8 oop

Link: http://voicesoftheelephpant.com/2014/03/11/interview-2-with-larry-garfield-drupal-8-object-oriented-programming/

QaFoo:
Learn OOD - to unlearn it again
February 11, 2014 @ 12:52:10

In this latest post to the QaFoo blog Tobias Schlitt recommends learning proper object-oriented design first before trying to worry about the interactions between the objects.

One topic we regularly teach in workshops for our customers is object oriented design (ODD), i.e. the art of crafting classes/interfaces in a way that the result is an easy-to-understand, maintainable and flexible code base. With the agile focus on shipping working software, some might consider the skill of OOD less important. One popular argument is that quick reaction to change is more important than designing objects and their interaction carefully. I personally look at it the exact other way around. This blog post summarizes why you need to learn OOD first, in order to avoid it to some degree again.

He's broken up the rest of the post into a few different topics reinforcing this idea:

  • Learning OOD the classical way
  • OOD in fast pace and agile
  • Refactoring is the key
  • Learning OOD to unlearn it

Finally, he makes the recommendation that all developers should learn about effective refactoring and automated testing to help create well-structured OOP applications.

0 comments voice your opinion now!
learn ood oop objectorienteddesign design object learn

Link: http://qafoo.com/blog/064_learn_ood_to_unlearn_it.html

Anthony Ferrara:
Beyond Object Oriented Programming
November 12, 2013 @ 11:56:36

Following up on his previous post talking about going "beyond inheritance" in object-oriented development in PHP, Anthony Ferrara has a new post extends the subject, focusing more on types of classes and how his thoughts would apply.

In the last post Beyond Inheritance, we talked about looking past "types" and reasoning about objects differently. The conclusion was that inheritance wasn't necessary for OOP, and often results in more problems than it solves. Well, let's go beyond that and explore more of what will come from treating objects as containers of behavior. Let's look at what this means for various kinds of classes.

He looks at five different class types and gives a brief summary of the concepts they represent - Representers, Doers, Plumbers, Translators and Makers. He then shifts over to investigating how this all applies to the SOLID development principles. He follows this pattern of thought through and looks at how it breaks things down into decomposable behaviors and, ultimately, functional programming/code structures (including the suggestions that creating ValueObjects is directly related).

0 comments voice your opinion now!
beyond oop types solid development functional valueobject

Link: http://blog.ircmaxell.com/2013/11/beyond-object-oriented-programming.html

Anthony Ferrara:
Beyond Inheritance
November 05, 2013 @ 13:08:24

In a previous post Anthony Ferrara looked at design patterns and their use (and usefulness) in modern applications. in this new post he continues the series but focuses more on a strategy to move past them related to inheritance.

In my last post, I talked about revisiting the concept of Design Patterns and questioned how useful it is to "learn" them. The conclusion that I came to was that you are better served by focusing on how objects communicate rather than traditional patterns. Well, that's not the only "traditional concept" that I think we should move beyond. So, let's talk about inheritance...

He starts with a bit of definition about what inheritance actually is (for a little context) related to classes, not traits or interfaces. He compares two ideas around this inheritance - the actual implementation of it in the code and the specification of it, the planning a "promise" the structure defines. He discusses the separation of these two ideas and that what matters is that the specification is implemented - how doesn't matter as much. He gets down to the most basic concept behind the idea of inheritance, the idea of a "contract", that defines the "agreement" the implementation puts into practice.

Finally, he gets down to what he calls "the key" behind inheritance and encapsulation of functionality into desecrate parts - behaviors. These allow you to know what kind of functionality comes from which class/object without having to guess. Methods have behaviors and objects are collections of these, combining to make a larger object-centric behavior.

Object Oriented Programming is all about abstraction. Each layer is an abstraction of code below it. Using "types" makes this difficult, because often we don't have real-world analogs to represent each layer. After all, an abstraction is specifically not a type. It's the concept behind it. With behaviors, this comes naturally.
0 comments voice your opinion now!
inheritance specification implementation contract behavior oop

Link: http://blog.ircmaxell.com/2013/11/beyond-inheritance.html

NetTuts.com:
Dates and Time - The OOP Way
October 24, 2013 @ 11:49:23

On NetTuts.com today there's a new tutorial they've posted showing how to use PHP's DateTime functionality in a more OOP kind of way. The DateTime extension lets you work both ways - procedural and OOP, with only slightly different syntax changes between them.

The Date/Time PHP extension is a set of classes that allow you to work with almost all of the date and time related tasks. It's been available since the release of PHP 5.2 and the extension introduced several new classes.

The tutorial first shows you some of the differences between just working with something like date and DateTime. From there they get into a bit more complicated things like:

  • Modifying dates/times
  • Working with multiple dates
  • Working with timezones
  • Using DatePeriods
  • Extending the current functionality

There's also two more "real world" usage scenarios included - defaulting to using UTC times and using the DateInterval to handle subscription payment logic.

0 comments voice your opinion now!
datetime tutorial oop introduction date time

Link: http://net.tutsplus.com/tutorials/php/dates-and-time-the-oop-way/

Brandon Savage:
The value of design patterns
October 21, 2013 @ 12:48:37

Brandon Savage has a new post today talking about the value of design patterns with his response to another post. He tries to put the emphasis back on making good OOP code instead of worrying too much about the actual design pattern.

Anthony [Ferrara] makes some great points in his article, and I highly encourage you to read it. But I want to address the perspective that he puts forward, which is that worrying about design patterns is less important than worrying about writing great object oriented code.

He relates design patterns to the sentence structures you learn when learning a new (spoken) language. He suggests that, while they're a good way for developers to communicate, they shouldn't be the only emphasis. When a developer becomes more fluent in a language, the patterns should become less important but are still a good structure for good development practices.

0 comments voice your opinion now!
oop designpattern value opinion fluent language

Link: http://www.brandonsavage.net/the-value-of-design-patterns/


Community Events





Don't see your event here?
Let us know!


zendserver introduction install series laravel package community podcast opinion deployment symfony interview unittest framework api library release language bugfix voicesoftheelephpant

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework