Chapter Review:

• What is an abstract class? How do you create and use one? (See page 184.)

An abstract class is a kind of "base class" that is not actually called -but forms a common foundation for other child classes.

• What is an abstract method? How do you create and use one? (See pages 184 and 185.)

a function that is part of an abstract class that is defined as abstract. The methodology of the function is defined in the extension class, NOT in the abstract class.

• When a class inherits an abstract method, what visibility can the subclass assign to that method? (See page 185.)

The same or weaker visibility. Thus, if protected abstract function x(){}, then the extended can be public or protected. A private abstract funciton would be useless - AND generates an error.

• What is an interface? How do you create one? How do you use one? (See page 191.)

Interface is another OOP technique to allow a defined set of functions and attributes to be implemented by a class. Best practice for creation is to precede the name with i to identify it easily from regular classes, thus, iMyInterfaceName {}, it contains only methods, and is used via the following: someClass implements iMyInterfacename{class code must define interface methods)}.

Side note: It seems to be one of those things that code managers/architects created to make sure classes contained certain things.

• What visibility must interface methods have? (See page 191.)

Public.

• What is a trait? How do you create one? How do you use one? (See page 197.)

Traits are a recent addition to PHP OOP 5.4 and allow for an inherited class to use an additional class beyond the parent in practice.

trait tSomeTrait {
// Attributes
function someFunction() {
// Do whatever. }
}

to use:

class someClass{
use tSomeTrait;
//rest of class
}

• What is type hinting? How do you perform type hinting? (See page 203.)

Type hinting allows use of a class name to "hint" and define a required method. Usage is:

class SomeClass {

function doThis( OtherClass $var) { }

}

• What are namespaces? Why are they useful? How do you crate a namespace? How do you reference namespaced code? (See page 207.)

Namespaces are like a file folder system for code development. Keeps code from multiple classes, developers etc from "tripping" over each other. Created by syntax: /subnamespace(optional)/subnamespace(optional)/namespacename;

The namespace name will need to precede the class name using the above syntax.

 

Toggle Sidebar