Archive for February, 2009

Blog Seperator
February 25th, 2009

Mini How To for PHP Abstract Classes

Warning: extremely nerdy content follows.

Object oriented programming is all the rage these days and PHP provides a fairly complete toolkit to be down with OOP (that’s Object Oriented Programming for non nerds).  PHP has gained in popularity for this very reason.  However, most of us don’t really go very deep into different OOP features like interface classes and abstract classes.  We wade in the shallow waters of plain old basic classes, either intimidated by or oblivious to the depths that OOP has to offer.

It’s time to get out of the kiddie pool… we’re going deep.

Let’s look at “abstract classes.”  While they don’t make for great party conversation, they are a powerful tool if used correctly.  Let’s create an example.

You need a class for users, which might look like this in it’s simplest form.


class Users {
public $username;
public $password;
...
function __construct() {
...
}
static function login($username, $password) {
...
}
public function logout() {
...
}
}

Simple enough.  But what if you need more than one type of user such as sales and customer?  You could create two classes, one for each.  The downside of that approach is you will have to maintain two different database tables and two classes.  That means if any changes have to happen, such as adding in a captcha, it has to happen in more than one place.  You would then have to change both classes and both tables.  It can get messy.

Abstract classes to the rescue!

Abstract classes allow you to have a common set of functions shared by all the classes that are extended from it.

abstract class Users {
public $username;
public $password;
...
function __construct() {
...
}
function login($username, $password) {
...
}
function logout() {
...
}
abstract function checkSale();
}

Notice we added a function here, but it’s set as abstract, it has no brackets ({}), and ends with a semi-colon. We also made sure to initiate the constructor for the parent class with “parent::__construct()” (be sure to pass any variables needed by the parent class).  Now comes the fun. We can create two separate classes that extend this class and add all sorts of functionality to each of them, but still inherit everything we’ve already created. In our example that would be “Customers” and “Sales”.

Now those who know a bit about OOP may ask, “why don’t we just create a normal class and extend it then?” First off, someone could still use the parent “User” class. This can create instability in the system since not all User objects would be created as Customers and Sales objects, but as the parent (Users). While YOU may know what you are doing, a programmer who follows you may end up pulling out hair and calling down curses on your head.

With an abstract class we don’t have to worry about that. You can’t create an object using an abstract class. You have to extend the class AND make sure to write a function for any of those abstract function lines we have in the parent class. If we don’t, PHP will throw an error. Here’s an example of a derived class.


class Sales extends Users {
public $salesGoal;
public $currentSales;
...
function __construct() {
parent::__construct();
}
function addSale($amount) {
...
}
// Here's the abstract function
function checkSale() {
... // make sure the sale happened, etc.
}
}

And the Customer class:


class Customer extends Users {
public $lastSale;
public $lastProduct;
function __construct() {
parent::__construct();
}
function addPurchase($item, $amount) {
...
}
// Here's the abstract function
function checkSale() {
... // do some other validation
}
}

Now we have two independent classes that share functionality and each have unique functionality. Neat!  Let’s look at the pros and cons for abstract classes:

Pros

  • You can have multiple classes that share functionality.
  • The parent class can’t be used to create objects, keeping things tidy and simple.
  • You can add shared functionality simply.

Cons

  • You can’t use the parent class, reducing flexibility.
  • If you don’t have a compelling reason to use abstract classes, you are introducing complexity instead of keeping it simple.
  • You have to use EVERY abstract function in a derived class, whether you need it or not.
February 25th, 2009 in Web Development | Comments (1)
Blog Seperator
February 23rd, 2009

You too, can have a cool iPhone icon!

iphoneIn our world today, the advances in technology are becoming better than ever… electric cars, music playing sunglasses, 3D movies and most importantly Facebook in your pocket at all times. But the absolute coolest thing out right now, and most brilliant piece of machinery known to man, has got to be the Apple iPhone [subliminal message: lifeBLUE loves Apple and they should send us stuff]. It basically does everything for you except the dishes and laundry (lets hope that’s coming soon). If you don’t have one, you’re practically living in the stone age. I mean, all the cool kids are doing it, why haven’t you? Along with its daily schedule, nifty calculator, weather information, high quality camera, and list of a million apps for you to choose from, the internet integration is outstanding. And what do all the great features and internet integration have in common? You get to them with a simple touch of a nice, shiny, glossy, rounded button. Who doesn’t love those icons? Who hasn’t brainstormed in their head ways they can use that same interface look, whether it be in a marketing campaign, a webpage design or simply wallpapering your house? It’s become a “trend”, these stylish little buttons.

The cool part is now you can make your own. Within the Safari internet browser, when bookmarking a website, you are now able to customize your own buttons by taking a screenshot of the page, creating even more icons on your home screens. Why just bookmark something when you can add a button directly from your main screen. Talk about convenience.

But let’s take this one step further. Have you ever noticed that when you bookmark a more well known, popular site, it doesn’t just take a screen capture, instead it already has its own default icon for you to use. Google has the “G” icon and Yahoo has the “Y” icon. So how do they do that? How neat would it be for you to design your own icon as well, for your personal website for everyone to see? Yahoo can, so we should be able to. Have no fear, you too can do this custom icon trick for your personal website as well and be just as savvy as those other big businesses, and all in about 3 easy steps.

  1. First of all start with a 57 x 57 canvas (pixels), and create your design.
  2. Save it as a PNG file named “apple-touch-icon.png”
  3. Upload this to the root directory of your website.
apple-touch-icon.jpg apple-touch-icon2.jpg
Your Image How It Appears

Leave it to Apple to do the rest, your design will automatically be given the curves it needs, along with the inside glow, your icon will fit right in with all the others.

That wasn’t hard at all! Now you’re just as cool as Apple and Facebook and when people (and yourself of course) bookmark your website, your newly designed icon will show up on their iPhone home screen. Go ahead, test it for yourself!

February 23rd, 2009 in Fun, Web Development | Comments (1)
Blog Seperator
February 9th, 2009

3 Reasons Why it is OK to be a NERD

We the people at lifeBLUE Media have become quite comfortable with the use of the word “nerd”. It is certainly not a derogatory term by any means. I would actually consider it almost a term of endearment, well not really, but praise nonetheless. Here are three reasons why you should hug the next person you cross sporting a pocket protector, taped glasses and high watered pants.  He might even be that big tall drink of water next to you at Starbucks that eats binary code for breakfast. You wouldn’t know he is the soul reason your mobile device has become something you could not live without.

1. NERDs fix things. A nerd is the guy you call frantically asking him to fix the computer that you actually just forgot to turn on (#1 rule of technical support). He is your family member you ask to take a look at your MP3 player when he (or she) comes over for Thanksgiving dinner. Nerds are your technical relief when franchised computer fix-it companies want to charge you $1,000 to fix your $600 laptop.

2. NERDs simplify your life. Justly stated, thank Bill Gates and the writers of MS Word. Can you imagine going back to a typewriter or handwriting your 25 page report for your college final? I don’t think so. Long have we taken spell check, sentence formatting, and 2.12 page spacing (that’s right you cheaters) for granted. Yes, it costs a little more than a pretty penny but how much is your time worth, not to mention, your household nerd already saved you $600 by fixing your laptop.

3. THE INTERNET! Need I really say more? Of course, originally the Internet was produced by the Rockwell New Mexico aliens who turned it over to the military, who then gave it to us little people for common household use. But it is the nerd’s of the world that bring it to your doorstep everyday. From building websites, computers and server management, it is the nerd’s of the world that are keeping our Facebook statuses updated. They create endless and mindless games, costing companies billions of dollars and free music thus putting our country’s musicians in the poor house (you didn’t hear it from me).

Always remember it is a “scorned” nerd that is spamming your email with tales of Nigerian princesses and causing us to pay thousands of dollars for spamware, malware, and whateverelseware. Hell hath no fury like a nerd scorned…trust me. So next time you see a nerd, give him a hug and say thank you, you just might need him someday.

February 9th, 2009 in Fun | Comments (1)
Blog Seperator
February 4th, 2009

What Does Your Logo Say About Your Company?

Take a look at the following major companies to get a feel for what their logos portray…

Folger's Logo Folgers - the background gives a feeling of a bold, bright, sun bursting over the horizon. The white letters symbolize clean, pure and simple.
HP Logo HP- The words “outside the box” and “creative” come to mind. They are trying to get across that they are not average and are a circle in a square world.
Citi Logo Citi - the red line above the logo is a symbol for an umbrella, with the “T” as the handle. It symbolizes safety. The colors and font give a feeling of all-american and traditional, as well as no-frillz or fluff.
Citi Logo Obama’s logo - the bright, light colors give a feeling of fresh and new. Red, white and blue have always been colors that evoke feeling of “all American” or national pride, but the colors are not the traditional shade. They are lighter, as his big running platform, “change”. The white circle symbolizes the sun rising over the horizon. The circle is also a symbol for “creative”, as well as his name, Obama.

In a society of choices, it is important to think about the message you are portraying, without saying anything at all. For example, Walmart has recently rebranded themselves with a new logo. Let’s take a look at how a slightly changed logo can send two very different messages:

Walmart’s previous logo, found below on the left, is in all caps with a simple blue text. There is practically nothing to it. This logo carries the message the bare minimal, simple, rough and low end. This is basically what Walmart was; a low end distributor, focused on low prices and nothing else. The new logo, found below on the right, bears a very different tone. It is a softer blue, slightly rounded edges and a yellow sun burst or flower. So what does it mean? What is the difference here? The new logo is softer, friendlier and emphasizes “live better”. Their brand shift also echoes this sentiment though opening a chain of “green” stores, as well as offering more environmentally friendly options in all of their stores.

Walmart's Old Logo Walmart's New Logo

The point here is that your brand tells the public everything they need to know about you. A simple change of font or shade of a color can make all the difference in the world. It tells whether you are serious, welcoming to children, creative, tech-savvy and so much more. Does your logo convey the right message of your company? What does your logo say about you? If you’re unsure, chances are so is your audience.

February 4th, 2009 in Marketing | Comments (3)
Blog Seperator
February 3rd, 2009

How Internet Explorer 6 Killed the Economy

The ’90s were good for a lot, but also brought us a lot of things we could really live without: carpenter jeans, the first Gulf War, The Macarena, and Internet Explorer 6.

Each have had long-lasting consequences– Carpenter jeans turned into carpenter shorts, vets returned home with Gulf War syndrome, the Macarena still lives on at ballparks across the nation, and of course, tons of wasted hours trying to support a browser that should have been kicked to the curb a long time ago.

As a web developer, one of my jobs is to make sure that our clients’ sites look great in all browsers.  For the most part, I get it right in browsers like Firefox, Safari, and Internet Explorer 7. But like 12.4 million (a semi-accurate-ish stat) other developers across the world, I spend entirely too much time having to piece together fixes to make these sites work and look good in Internet Explorer 6. That time could be better spent working on new business, improving upon old business, or innovating and creating new products for our company.

Just look at this completely fictitious yet surprisingly probable graph I came up with:

As you can see,  US Workplace Productivity (for web developer/designers)  is severely affected by the growth of the IE6 market share. A lack of productivity correlates to our debt and economic tailspin, and yet still today thousands of corporations insist on making Internet Explorer 6 the standard browser choice for their employees. I say it’s time for a revolution.  Shut down that browser and head over to Firefox  to get their latest, or visit Microsoft and grab Internet Explorer 7. While you’re at it,  replace your carpenter jorts with a nice pair of Diesel jeans and ditch your Michael Bolton tapes for some downloads of Wilco or The Killers.

February 3rd, 2009 in Web Development | Comments (3)