Understand basic OOP concepts, such as inheritance, encapsulation, and polymorphism. pot

50 310 0
Understand basic OOP concepts, such as inheritance, encapsulation, and polymorphism. pot

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

this print for reference only—size & color not accurate spine = 0.911" 392 page count DAVID POWERS In this book you’ll learn how to: Produce code that’s easier to maintain by adopting OOP techniques. Use best practices by implementing basic design patterns. Simplify complex code through encapsulation. Unlock the secrets of the Standard PHP Library. Generate your own news feed using Really Simple Syndication (RSS). P HP is easy to learn and a great way to add dynamic functionality to web sites, such as sending email from online forms and generating database-driven content. But there soon comes a time when you realize you’re writing similar scripts over and over again. By adopting an object-oriented approach, you can avoid the need to reinvent the wheel every time, creating scripts that are reusable, easier to understand, and easier to maintain. The main barrier to object-oriented programming (OOP) is that it’s based on unfamiliar concepts, such as objects, classes, interfaces, encapsulation, and polymorphism. This book strips away the mystique and explains each concept in an approachable and understandable way. It provides a gentle but fast-paced introduction to OOP as it applies to PHP. Another barrier to the adoption of OOP among PHP developers has been the slow migra- tion from PHP 4, which used a radically different—and inferior—object model. Now that PHP 4 has come to the official end of its life, this book concentrates exclusively on using OOP with PHP 5 and 6. So you can be confi- dent that you’re learning skills that won’t be out of date almost as soon as you put the book down. Through a series of practical projects, this book shows how OOP can be used to group related functions in a portable manner. The projects include a validator for fil- tering user input, a class that avoids the need to remember all the esoteric PHP date formatting codes, and an XML generator—everyday requirements for a lot of develop- ers. Although the emphasis is on learning how the code works, if you’re in a hurry, the PHP classes used in the book can be downloaded from the friends of ED web site and incorporated into existing sites with a minimum of effort. The book is aimed at intermediate developers with a good understanding of PHP basics, such as variables, arrays, functions, loops, and conditional statements. It provides the necessary groundwork for advancing on to using an object-oriented framework, such as the Zend Framework, and taking your PHP coding skills to the next level. Powers CYAN YELLOW MAGENTA BLACK PHP OBJECT-ORIENTED SOLUTIONS Understand basic OOP concepts, such as inheritance, encapsulation, and polymorphism. Extend core PHP classes. Design and create your own classes for PHP 5 and 6. Also Available US $36.99 Mac/PC compatible www.friendsofed.com http://foundationphp.com/ SHELVING CAT EG OR Y 1. PHP Available from Apress ISBN 978-1-4302-1011-5 9 781430 210115 5 3 6 9 9 [...]... underwent comprehensive revision and enhancement when PHP 5 was released in July 2004, and the PHP 5 object-oriented programming (OOP) model remains essentially unchanged in PHP 6 The purpose of this book is to help you leverage those features to make your code easier to reuse in a variety of situations I assume you’re familiar with basic PHP concepts, such as variables, arrays, and functions If you’re not,... take a look at the basic building blocks of OOP: classes and objects See http://en.wikipedia.org/wiki/Object-oriented_programming for a more detailed background to OOP Using classes and objects Many computer books begin explaining OOP by using a car as an example of an object, describing the number of wheels or color of the bodywork as typical properties, and accelerate or brake as methods Although... when you extend the built-in PHP DateTime class The extended class inherits all the basic characteristics of the DateTime class and creates an object to store a date, time, and time zone Some of the original class’s methods, such as for setting and getting the time zone, are fine as they are, so they are inherited directly However, the original DateTime class doesn’t check a date for validity, so you’ll... protected, and private properties and methods in the next chapter Encapsulation also makes the final code much simpler and easier to understand, and this is where the example of a car as an object begins to make sense Unless you’re a motor mechanic or enthusiast, you don’t need to know the details of the internal combustion engine to get in a car and drive It doesn’t matter whether it’s an old-fashioned gas... head, but its function is basically the same (eating, breathing, seeing, and so on), so we use the same word without confusion OOP applies this to programming by allowing you to give the same name to methods and properties that play similar roles in different classes Each class and object is independent, so method and property names are intrinsically associated with the class and any objects created... characteristics from your parents, and developed new ones of your own, a child class or subclass in OOP can inherit all the features of its parent (or superclass), adapt some of them, and add new ones of its own Whereas humans have two parents, in PHP, a child class can have only one parent (Some objectoriented languages, such as Python and C++, permit inheritance from more than one parent class, but PHP supports... practice, showing you how to create and use your own classes and objects, as well as covering object-oriented features that have been built into core PHP since version 5 You don’t need to be a PHP expert to follow this book, but you do need to know the basics of writing your own PHP scripts So, if you’re comfortable with concepts such as variables, loops, and arrays, and have ever created a function,... taken by OOP has two distinct advantages, namely: Code reusability: Breaking down complex tasks into generic modules makes it much easier to reuse code Class files are normally separate from the main script, so they can be quickly deployed in different projects Easier maintenance and reliability: Concentrating on generic tasks means each method defined in a class normally handles a single task This... use footDown(), squeezeHandle(), or pedalFaster() depending on the type of car Polymorphism and encapsulation go hand in hand, with polymorphism providing a common interface and encapsulation taking care of the inner details In a web site context, you might create different classes to interact with MySQL and SQLite databases Although the code needed to connect to each database and run queries is different,... differs from a class What terms such as encapsulation, inheritance, and polymorphism really mean How the object-oriented model has developed in PHP Which tools make it easier to work with classes in PHP I don’t intend to bombard you with dense theory The emphasis will be on gaining practical results with a minimum of effort If you’re lazy or in a hurry, you can just use the PHP classes in the download . framework, such as the Zend Framework, and taking your PHP coding skills to the next level. Powers CYAN YELLOW MAGENTA BLACK PHP OBJECT-ORIENTED SOLUTIONS Understand basic OOP concepts, such as inheritance,. object-oriented programming (OOP) is that it’s based on unfamiliar concepts, such as objects, classes, interfaces, encapsulation, and polymorphism. This book strips away the mystique and explains each. of PHP basics add OOP to their skill set. So, what is OOP? To oversimplify, OOP groups together functions (known in OOP- speak as “methods”) in classes. In effect, a class can be regarded as a function

Ngày đăng: 27/06/2014, 12:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan