13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

160 Chapter 6 Object-Oriented <strong>PHP</strong><br />

Underst<strong>and</strong>ing Object-Oriented Concepts<br />

Modern programming languages usually support or even require an object-oriented<br />

approach to software development. Object-oriented development attempts to use the<br />

classifications, relationships, <strong>and</strong> properties of the objects in the system to aid in program<br />

development <strong>and</strong> code reuse.<br />

Classes <strong>and</strong> Objects<br />

In the context of OO software, an object can be almost any item or concept—a physical<br />

object such as a desk or a customer; or a conceptual object that exists only in software,<br />

such as a text input area or a file. Generally, you will be most interested in objects,<br />

including both real-world objects <strong>and</strong> conceptual objects, that need to be represented in<br />

software.<br />

Object-oriented software is designed <strong>and</strong> built as a set of self-contained objects with<br />

both attributes <strong>and</strong> operations that interact to meet your needs. Attributes are properties<br />

or variables that relate to the object. Operations are methods, actions, or functions that the<br />

object can perform to modify itself or perform for some external effect. (You will hear<br />

the term attribute used interchangeably with the terms member variable <strong>and</strong> property, <strong>and</strong><br />

the term operation used interchangeably with method.)<br />

Object-oriented software’s central advantage is its capability to support <strong>and</strong> encourage<br />

encapsulation—also known as data hiding. Essentially, access to the data within an object is<br />

available only via the object’s operations, known as the interface of the object.<br />

An object’s functionality is bound to the data it uses.You can easily alter the details<br />

controlling how the object is implemented to improve performance, add new features, or<br />

fix bugs without having to change the interface. Changing the interface could have ripple<br />

effects throughout the project, but encapsulation allows you to make changes <strong>and</strong> fix<br />

bugs without your actions cascading to other parts of the project.<br />

In other areas of software development, object orientation is the norm, <strong>and</strong><br />

procedural or function-oriented software is considered old fashioned. However, most<br />

web scripts are still designed <strong>and</strong> written using an ad hoc approach following a functionoriented<br />

methodology.<br />

A number of reasons for using this approach exist. Many web projects are relatively<br />

small <strong>and</strong> straightforward.You can get away with picking up a saw <strong>and</strong> building a wooden<br />

spice rack without planning your approach, <strong>and</strong> you can successfully complete the<br />

majority of web software projects in the same way because of their small size. However,<br />

if you picked up a saw <strong>and</strong> attempted to build a house without formal planning, you<br />

wouldn’t get quality results, if you got results at all.The same is true for large software<br />

projects.<br />

Many web projects evolve from a set of hyperlinked pages to a complex application.<br />

Complex applications, whether presented via dialog boxes <strong>and</strong> windows or via dynamically<br />

generated HTML pages, need a properly thought-out development methodology.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!