 | News Feed |
Sections
|
| feed this: |  |
Debuggable Blog: Programming Psychology II Private methods
by Chris Cornutt July 08, 2008 @ 08:44:58
According to Felix Geisendorfer's newest post on the Debuggable blog, he thinks that "private and protected methods and properties are one of the most stupid concepts of OOP."
This is a thought I first shared at CakeFest Orlando this year, but could not explain properly at the time.
He illustrates with an example of a protected "balance" variable in a BankAccount class. Sure, it's marked as private but less skilled programmers might not use it that way. He recommends a method without the getters/setters to help make the usage of the variable a bit simpler. He also suggests that using protected/private scoping helps to promote "crappy code" - using them to provide a sort of protection for code that you either don't want getting used or hiding it away so the API can't get at it.
voice your opinion now!
private method protected bad code concept stupid getter setter
DevShed: More on Private Methods with PHP 5 Member Visibility
by Chris Cornutt June 25, 2008 @ 13:58:20
DevShed finishes off their series looking a private, public and protected variables and methods in classes with this final look a private methods in PHP5 object-oriented programming.
It's time to leap forward and tackle this final article of the series, which will be focused on covering some additional aspects concerning the use of this kind of class method. In addition, I'll teach you how to utilize the "final" keyword, which is included with PHP 5, to prevent the methods of a specific class from being overridden by any subclass.
They work from a hands-on example to show how they can work with private methods (expanding a bit from last time) and how to use the "final" keyword to restrict any and all modification for a method.
voice your opinion now!
php5 tutorial oop member visibility method property final private
DevShed: Utilizing Private Methods with PHP 5 and Member Visibility
by Chris Cornutt June 19, 2008 @ 07:58:51
DevShed has posted the fifth part of their series looking at the visibility keywords on PHP5's object oriented support today. They've already looked at private, public and protected properties in a class, now they look at the use of making methods private to restrict their use/extension.
Of course, when it comes to specifying how visible a certain class property or method will be, you know that PHP 5 permits you to work with three distinct levels of access, called "public," "protected," and "private" respectively. [...] As you may have noticed, however, I've not taught you how to define private methods yet, which is something that can definitely be very useful if you want to restrict the access to your classes from the outside more severely.
The tutorial shows the creation of a class with private properties and then expands it to include a private method. Then they call it from an object, an example of the error PHP kicks back is there too. He also includes the concept of a "getter" to call the private function from a public one.
voice your opinion now!
private object oriented php5 method tutorial getter
Michael Kimsal's Blog: PHP, Groovy and language evolution
by Chris Cornutt May 29, 2008 @ 12:52:07
In a new post Michael Kimsal does a good job comparing the rise of PHP5 (and what it brought with it) to his language of choice these days - Groovy.
I remember when PHP5 first came out having 'discussions' with a number of people who insisted that PHP5 was way better than 4. [...] Basically, intentions were made clearer with things like "public protected private" (PPP),but I have not yet seen any web project get done faster or dare I say even much *better* due to those sorts of things. [...] This isn't specifically saying PPP is necessarily bad, but that PHP could have addressed the issue in a fashion more suitable to dynamic languages. Keep reading for an example.
His comparison is to how Groovy handles properties in a class - everything is private unless declared otherwise. This could be ported (somewhat) over to PHP and would eliminate the need to search&replace all over the code for the right variables.
voice your opinion now!
groovy java language evolution php5 private public protected
DevShed: Protecting PHP 5 Class Data with Member Visibility
by Chris Cornutt May 22, 2008 @ 09:37:05
In this new tutorial posted to DevShed, they take a look at working with classes in PHP5, specifically using the keywords for "member visibility" to make your classes a bit more structured.
The previous concept can also be applied successfully when it comes to defining the visibility of properties and methods in PHP classes. [...] Using the jargon of object-oriented programming, this capacity is widely known as member visibility. This capacity allows PHP programmers to establish whether the set of methods and properties of a specific class will be public, protected, or private.
They start more generally by looking at how to set up the variables globally and then move down the line talking about restrictions (private/protected/public) and how to get to them in the scripts outside the class.
voice your opinion now!
visibility class tutorial private protected public php5
PHP in Action: Public constructors considered harmful
by Chris Cornutt May 05, 2008 @ 10:21:33
According to the PHP in Action blog, public constructors can be hazardous to your (application's) health and should be replaced.
Everybody who writes object-oriented code knows about constructors. You need them so the program knows how to instantiate objects, right? And you especially need them when a lot of things have to be done while instantiating an object. [...] So why would I be skeptical of public constructors?
The solution, as he sees it, is to make a "constructor" that's actually called statically with parameters that returns an instance of the class it's in as well as performing the action. He argues that this can help make the code much more readable for some types of method calls.
voice your opinion now!
public constructor harmful replace private instance
PHPBuilder.com: Class Inheritance with PHP
by Chris Cornutt February 18, 2008 @ 07:58:00
On PHPBuilder.com today, there's a new tutorial that takes a beginning look at PHP5's class inheritance model.
There are many benefits of inheritance with PHP, the most common is simplifying and reducing instances of redundant code. Class inheritance may sound complicated, but think of it this way. Consider a tree. A tree is made up of many parts, such as the roots that reside in the ground, the trunk, bark, branches, leaves, etc. Essentially inheritance is a connection between a child and its parent.
They choose to go with a "car" illustration instead and show how a child of the Product class (Car) can access the private properties of the parent. They also include an example of it in action with a bit of HTML output.
voice your opinion now!
inheritance class php5 object private protected public tutorial
Tobias Schlitt's Blog: Reflecting private properties
by Chris Cornutt February 15, 2008 @ 12:02:00
Tobias Schlitt has posted a handy tip about using the Reflection API in PHP5 - specifically its accessing of private properties in a class.
I recently stumbled over reflecting private properties in PHP again. As you might know, this was not possible until now and if you tried this [code] PHP thanked it to you with this [error that is cannot access a non-public member].
He notes that, while the behaviour is correct, it still makes things like metaprogramming impossible. So, what's a developer to do? Patch it of course! Tobias and Derick Rethans persuaded two other developers (Derick and Marcus Borger) to include a patch that allows the Reflection API to see these private variables.
To make it work, you have to use the setAccessible method on the Reflection object to set which of the properties you want to be able to get at.
voice your opinion now!
reflection api setaccessible private properties
|
Community Events
Don't see your event here? Let us know!
|