KillerPHP Blog

Object Oriented PHP

Why you should NEVER use inheritence in your PHP OOP Code!

April 9, 2014

franken-software
Hi!

First all of, I have to say that I love this guy on the right!!

🙂

Anyone who knows object oriented programming is probably having kittens now! How can a nerd like Stef be dissing one of the fundamental tools in our OOP toolbox? Isn’t inheritance one of the key tools that makes code reuse possible?

Well, only in the case of foundation code. Very few of use write that kind code. Most of us are writing business objects and business objects should be using interfaces and object composition.

What is foundation code?

Think the core of web servers, the core engines in database servers. All the stuff that is pretty much written.

Share object code as complete objects, leave the code alone!

Code Reuse doesn’t come so much from reusing code found in one class and using inheritance to bring it into another. No, it’s more about reusing objects across projects and reusing COMPLETE objects within the same project.

Composition over Inheritance

Favor combining objects (this is called composition) rather than creating new objects that inherent functionality from parent classes. Why?

Because inheritance creates fragile dependencies – if some nerd comes a long and decides to rewrite some of your base classes – you will be screwed! I’ve seen it firsthand. It’s not a pretty site: nerds screaming and yelling, app functionality breaking in 10 different places … nerds throwing wussy punches with the intent to do damage.

.. But since they are nerds, no one really gets hurt.

With composition, your objects are loosely bound. That means it’s easy to swap objects in an out of your code base, since your objects are not dependent on the INTERNALS of another object – something you get (unfortunately) with inheritance.

Keep your objects small, highly focused and dumb.

Objects should have very specific task and they should be dumb to what’s going on around them.

Objects should take in an input and spit out a generic output. You don’t want the behavior of your objects to be easily influenced by outside forces. If you want to modify what an object does for you, just grab the output from said object and modify the OUTPUT with another objects methods.

… Keeps the objects dumb I says!

Stefan Mischook
killerPHP.com

read more


Obamacare Websites Failed because it looks like Spaghetti.

November 17, 2013

spaghetti code

Best way to not build a massive website: load up a canon of nerds and fire them at said website.

🙂

Ok, let’s define that a little better! In a nutshell:

A very large complex software system, has to be designed as a set of smaller independent systems, that communicate with each other using a common set of protocols. These systems/software, should be have a fairly narrow scope in terms of what they do. That means, don’t try to make your software into a ‘swiss army knife’ of functionality.

… This is basic OOP programming but it seems that in real life, many software developers seems to forget this simple principle.

Separating Concerns, or Defining the Logical Parts of Software

The hardest part of architecting software, is figuring out how to break it down into its’ logical components. One common way to do this, is to look at a software from the point of view of the users … for example:

– user
– administrator

So in this case, you might break your software down by ‘user’ functionality and ‘administrator’ functionality. So you would have one team working on the ‘user’ app and another working on an ‘administrator’ app.

Connecting the two Apps together

In case of most PHP apps, you will be tracking information with a MySQL database and so you can use the database as the bridge between the user part of your program and the administrator part. Doing so can really simplify development and it makes it easier to have programmers work independently – without having to talk too much with people working on the other app.

A good Software Architect is Needed!

Of course, when you are developing apps like this, you first need to have an experienced architect who can properly structure the project so that the developers of each part (user and admin) are not stepping on each others toes!

What to take away?

The above example is just an example. For many projects, dividing the app by user type may not make any sense! The key thing you want to take away is that you should look to create your software so that the major functions (and the code associated) is isolated from the code used in other major functions found in your system.

I hope that helps,

Stefan Mischook
killerPHP.com

read more


PHP Frameworks Explained

February 26, 2013

Hi,

So you know a little PHP and you’ve heard about PHP frameworks like Zend, CodeIgniter and Laravel but you have no idea what they really are and why you might want to learn them … if this is you, watch this video:

If you like the video, be social about it and let people know!

Stefan Mischook
killerPHP.com

read more


New Video Tutorial: Build A Content Management System

June 1, 2011

I am happy to announce yet another screencast tutorial for all you nerds out there: Build A Content Management System.

OK, not the most exciting title, but still an exciting course for those PHP nerds who want to go from PHP basics and get into building a full-fledged PHP application from scratch.

Learn how to build a content management system that provides a website all the tools needed to allow basic web users to manage the website content with ease. Over 6.5 hours of tutorials over 41 videos!

Here are some details about the video tutorial:

This course is aimed at intermediate level web developers, demonstrating how to build a basic PHP based content management system that uses object oriented programming techniques and implements the MVC pattern.

Along the way, I cover a wide range of technologies, including HTML and CSS, a bit of javascript/jQuery/AJAX and PHP/MySQLi. I also show how to integrate Colorbox (a jquery plugin) and TinyMCE (for the WYSIWYG functionality.)

Read more: Building a PHP based CMS

Check out the CMS course sample videos

Thanks,

Stefan Mischook

read more


What are ORM Frameworks?

December 8, 2009

Database Image

In the following article we will learn a few things about ORM frameworks:

  • What they are.
  • What they do.
  • When and why to use them.
  • And finally, what ORM options PHP’ers have.

Let’s start …

If you’re working with PHP, you will certainly find yourself working with relational databases (like MySQL) sooner or later. Anyone who has ever built a reasonably complex web application knows, that the SQL can get really hairy at times – especially when you consider all the data filtering that you have to deal with!

ORM frameworks to the rescue!

ORM is yet another nerd-acronym, it is short for Object Relational Mapping. In a nutshell, an ORM framework is written in an object oriented language (like PHP, Java, C# etc…) and it is designed to virtually wrap around a relational database. If you look at the name (ORM), it basically translates into: mapping objects to relational tables.

There are many different competing ORM frameworks out there, because many nerds have their own ideas as to how to best do things – nothing new here! But you know what, some of these nerds are right … not all ORM frameworks are created equal.

(more…)

read more


Live Webinar on Google Wave and the Zend Framework

November 16, 2009

Hi Guys,

My good buddy and right-hand-nerd, Jon is being flown down to do a live webinar for the Zend geeks at Intuit. It seems the accounting giant has recognized Jon’s ability to take the complex and make it seem simple.

Just in case you don’t know, Jon is the author of our crazy cool shopping cart tutorial and our new series on advanced PHP.

… Jon is starting to realize that my choice to go with the Zend Framework a few years ago made sense. Actually, it made dollars and cents!

🙂

OK, bad nerd humor … I know. I’m just low on material that isn’t profanity laced.

If you want to know WHY, after looking at all the other PHP frameworks out there, that I thought the Zend Framework was the best choice long term (even back when Zend was still in Beta) .. you’re going to have to ask!

Anyway here is the official announcement:

Jon Lebensold, author of the popular PHP Shopping Cart and founder of Zendcasts.com will be writing a Google Wave Gadget in Boston at Intuit’s East coast office. Intuit is setting up a live webinar which you can attend by registering on the Zendcasts website.

Zendcasts.com began this year with the hope of assisting intermediate PHP developers further their Zend Framework skills. If you’re a PHP developer interested in building apps on Google Wave or want to watch someone build an AJAX application with web services like Google Wave and Intuit’s QuickBase, this free webinar will be worth spending a lunch hour at your desk.

The webinar takes place Wednesday, November 18 at 12:00 (noon) Eastern Standard Time (GMT -05:00).Register online now.

Here’s the banner:

qb-gwave-promo

Just in case you are not familiar with Quickbase … just click on the link.

That’s it for today. But coming soon, I will have some pretty big news … actually, the biggest thing to come to killerphp.com since we ordered that huge pizza! Ok, even bigger than that!!

😉

Stefan Mischook
www.killerphp.com

read more


Getting into PHP6 and Advanced PHP Concepts Part 7

November 6, 2009

Hi,

In our never ending quest for pure PHP nerdness, we continue our look at advanced PHP. This is video 7 of a series of videos where we explore PHP6 and other advanced PHP concepts, concepts often seen in PHP frameworks like Zend, PHP Cake and others.

The video:

More to come.

Stefan Mischook
www.killerphp.com

read more


Getting into PHP6 and Advanced PHP Concepts Part 2

October 20, 2009

boxshot-advphp

Hi everyone,

As promised, here is my second installment of our new PHP video tutorial course that covers more advanced PHP subjects including:

– PHP 6
– Advanced PHP architectures seen in PHP frameworks like Zend, CakePHP etc
– Magic methods
– anonymous functions
– namespaces

Etc

The second video:

Just in case you missed it, here is the link to the first part of Getting into PHP6.

Thanks for watching,

Stefan Mischook
www.killerphp.com

read more