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

Master Zend Framework:
Configuring the ServiceManager with Abstract Factories
July 23, 2014 @ 13:41:10

On the Master Zend Framework site today Matthew Setter has a new post covering the configuring of the service manager using abstract factories.

One of the best features about Zend Framework 2 is undoubtedly the ServiceManager; because it makes it almost painless to configure and retrieve services in a consistent and predictable manner, anywhere in your application, at any time. [...] But the catch is, there's quite a bit to learn if you want to use it properly. As well as that, there's quite a number of ways to use it.

He walks you through some of the pros and cons of the various ways to work with the ServiceManager and where the factories fit in. He takes a bit of time to introduce the concepts behind abstract factories and how to define them in a Zend Framework v2 application. He finishes out the post with a more practical, working example using the interfaces provided to get a "MyUserTable" service.

0 comments voice your opinion now!
configure servicemanager abstract factory tutorial screencast

Link: http://www.masterzendframework.com/servicemanager/configuring-servicemanager-with-abstract-factories

SitePoint PHP Blog:
Abstract File Systems with Flysystem
April 07, 2014 @ 11:27:59

The SitePoint PHP blog has a new tutorial today from Lukas White showing you how to work with abstract file systems that aren't local. In this case, the file system is virtual and living on a remote system.

Reading and writing files is an integral aspect of any programming language, but the underlying implementation can vary enormously. For example, the finer details of writing data to the local filesystem compared to uploading over FTP is very different - yet conceptually, it's very similar. In addition to old warhorses like FTP, online storage is increasingly ubiquitous and inexpensive - with scores of services available such as Dropbox, Amazon's S3 and Rackspace's Cloud Files - but these all use subtly different methods for reading and writing. That's where flysystem comes in.

He shows how to install the flysystem library (via Composer) and a few examples showing how to make connections to:

  • an Amazon S3 instance
  • a Dropbox account
  • SFTP
  • even Memcache

Examples of both reading and writing to this virtual system are also included as well as a few other features like handling visibility, listing files/directories and mounting the remote filesystem locally.

0 comments voice your opinion now!
abstract filesystem flysystem library tutorial

Link: http://www.sitepoint.com/abstract-file-systems-flysystem

Pixelstech.com:
Should we use Abstract class or Interface?
April 18, 2013 @ 09:22:23

On the Pixelstech.com site today there's a new post that talks about the differences between abstract classes and interfaces and when's the best time to use either (or both).

When we write programs, we may often get into a situation where we don't know whether we should use Abstract class or Interface when we want to define an abstract object. These two are very similar and they are interchangeable. On Stackoverflow, this question is asked many times, it's related to many programming languages. Also in the official documentation of PHP regarding the Abstract class and Interface, people are arguing about this. To understand this question, we need to understand their differences and use scenarios.

They provide examples of abstract class and interface usage with one of the main differences being that you can define functionality in abstract classes. There's also examples showing classes that extend the abstract class while implementing the interface at the same time, helping to define the object structure to an even finer level.

0 comments voice your opinion now!
abstract class interface tutorial choice extends implements

Link: http://www.pixelstech.net/article/1366044255_Should_we_use_Abstract_class_or_Interface_

QaFoo Blog:
Abstract Classes vs. Interfaces
October 02, 2012 @ 12:29:56

On the QaFoo.com blog Kore Nordmann shares some insight about the difference between abstract classes and interfaces and how they can be used effectively/correctly.

Features of object oriented languages are often use from a purely technical perspective, without respect to their actual semantics. This is fine as long as it works for you, but might lead to problems in the long run. In this article I discuss the semantical differences between abstract classes and interfaces. I also outline why following the semantics of those language constructs can lead to better code.

He defines "class" and "interface" before he gets too far into the differences, stating that a "class" is more of a "type" while an "interface" describes the type and the structure to use it. He also talks about how to tell them apart (when to use each). There's also some examples and "hints" to help you determine good and bad examples of interfaces and when an abstract class might be a better answer.

0 comments voice your opinion now!
abstract class interface compare tips definition


PHPMaster.com:
Overriding Strategy Logic - The Template Method Pattern
September 25, 2012 @ 08:58:01

On PHPMaster.com there's a new tutorial posted talking about the Template Method Pattern to help make some sense (and make easier to use) your implementation of the Strategy pattern.

This bring us back to the question whether it's feasible to eliminate duplicated strategy logic via Inheritance rather than switching over to plain Composition. Indeed it is, and the clean up process can be conducted through an ubiquitous pattern known as Template Method. [...] Simply put, there's a base class (usually an abstract one), which declares a concrete method (a.k.a. the template) responsible for outlining the steps or hooks of a certain algorithm. Most of the time the base type provides boilerplate implementation for some of those steps and the remaining ones are delegated to subclasses.

The subtypes then override the base's functionality and extend it with their own. They show an example of this by making a jQuery image slider (using this plugin) , an "AbstractCycleSlider" class and two subclasses for two other types - "FadeSlider" and "ScrollSlider", each outputting their own HTML. It also shows how to implement a slider using a different plugin and output both in the same script.

0 comments voice your opinion now!
strategy logic designpattern template method abstract subtype


PHPMaster.com:
Subtype Polymorphism - Swapping Implementation at Runtime
September 17, 2012 @ 12:48:52

On PHPMaster.com there's a new tutorial from Alejandro Gervasio about subtype polymorphism. It sounds a little scary, but really it's just a look at sub-objects that inherit from parents and how to swap them around at runtime to do different things.

In this article I'll show you how to exploit the virtues that Polymorphism offers through the development of a pluggable cache component. The core functionality can be expanded later to suit your needs through the development of additional cache drivers.

He starts off with the definition of an interface to provide structure to the sample application (the CacheInterface) and implements it in two different subtypes - a FileCache and an AppCache (using the file system and APC, respectively). He builds on these and creates a "View" that uses these caching systems to generate and save the output to a cache for use later in the execution.

0 comments voice your opinion now!
subtype polymorphism tutorial interface abstract caching


Refulz.com:
Traits in PHP - Multiple and Nested Traits
May 28, 2012 @ 15:16:29

On the Refulz.com blog there's a new tutorial posted looking at traits (and nested traits) in PHP including examples of them in use and how to create your own.

Traits is a good new addition to PHP language. In our series about the new features of PHP 5.4, we reviewed the concept of Traits in PHP. The introductory article talks about what the traits are and what is the general syntax of Traits in PHP. The second article attempts to explain why we need traits.

The tutorial shows you how to define a custom trait use things like abstract methods, nesting them by making them "users" and how to use multiples at the same time (comma-separating).

0 comments voice your opinion now!
traits multiple nested tutorial abstract


Sebastian Göttschkes' Blog:
Testclasses for symfony2
April 13, 2012 @ 11:57:53

Sebastian Göttschkes has a new post to his blog about a set of abstract base testing classes he's developed to help with the functional, unit and validation testing of his Symfony2-based applications.

So, when developing with symfony2, I rely on my tests. They are my safety net and without them, I get a little nervous after every change. Does everything work? Did I forget anything? So I developed some classes which I extend. They work on top of PHPUnit and the symfony2 WebTestCase. The classes are used by my different types of Tests: UnitTests, ValidationTests, FunctionalTests (as well as IntegrationTests).

Code for each type of testing base class is included in the post showing how he extends the based PHPUnit test case for unit testing and the Symfony WebTestCase for validation and functional testing. Each one of the classes are ready to use and give you some handy helper methods too.

0 comments voice your opinion now!
testing abstract class validation unittest functional


DevShed:
Effects of Wrapping Code in Class Constructs
December 29, 2011 @ 10:06:58

DevShed has a new tutorial posted today looking to help you counteract the bad practice of wrapping procedural code in "class" constructs and provide some useful suggestions of how to avoid it.

Static helpers seem to be a great idea at first glance, as they're reusable components that don't require any kind of expensive instantiation for doing common tasks [...]. But the sad and unavoidable truth is in many cases they're simply wrappers for procedural code, which has been elegantly hidden behind a "class" construct. So what's wrong with this? Well, even in the most harmless situations, when you use a static helper that produces a deterministic output, you're actually throwing away the advantages that OOP provides.

To illustrate, they create a basic validation class that can check for things like valid emails, float values, integers and URLs using PHP's filter_var function. They point out that the class is difficult to extend and that it is doing too many things to be correctly considered a "piece" of functionality. To correct the problem, they opt for a different approach - an abstract class acting as an interface to structure custom validators against. This provides set/get methods for things like the error message and value to evaluate. The implementation of the validators on top of this class is coming in the next part of the series.

0 comments voice your opinion now!
tutorial constant static method interface abstract class


DevShed:
Building Concrete Validators
December 22, 2011 @ 11:24:25

On DevShed.com today there's the first part of a two-part series showing how to build self-contained validator objects that can be used to test the format of user input for validity.

In this two-part tutorial, I show why the use of static helper classes can be detrimental to building robust and scalable object-oriented applications in PHP (though you should take into account that the concept is language agnostic). I also implement a set of instantiable, fine-grained validators, which can be easily tested in isolation, injected into the internals of other objects, and so forth.

Their set of "concrete validators" are all based off of a validator interface/abstract class and check things like email formatting, floats, integers and URLs. Also included are a few examples of using the validators in a sample script.

0 comments voice your opinion now!
validator tutorial test data interface abstract class



Community Events





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


introduction threedevsandamaybe experience community symfony2 configure testing unittest interview podcast release developer list language series laravel opinion install code framework

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