Solved

please explain all the type for local. What is elements?

Posted on 2014-03-15
5
196 Views
Last Modified: 2014-03-17
from Larry Ulman php tutorial

<?php # Script 7.5 - WorkUnit.php
// This page defines a WorkUnit class which uses the Composite pattern.
// This page also defines Team and Employee classes, which extend WorkUnit.

/* The WorkUnit class.
 * The class contains two attributes: $tasks and $name.
 * The class contains five methods: __construct(), getName(), add(), remove(), assignTask(), and completeTask().
 */
abstract class WorkUnit {
    
    // For storing work to be done:
    protected $tasks = array();

    // For storing the employee or team name:
    protected $name = NULL;
    
    // Constructor assigns the name:
    function __construct($name) {
        $this->name = $name;
    }
    
    // Method that returns the name:
    function getName() {
        return $this->name;
    }
    
    // Abstract functions to be implemented:
    abstract function add(Employee $e);
    abstract function remove(Employee $e);
    abstract function assignTask($task);
    abstract function completeTask($task);
    
} // End of WorkUnit class.

/* The Team class extends WorkUnit.
 * The class has one new attribute: $_employees.
 * The class has one new method: getCount().
 */
class Team extends WorkUnit {
    
    // For storing team members:
    private $_employees = array();
    
    // Implement the abstract methods...
    function add(Employee $e) {
        $this->_employees[] = $e;
        echo "<p>{$e->getName()} has been added to team {$this->getName()}.</p>";
    }
    function remove(Employee $e) {
        $index = array_search($e, $this->_employees);
        unset($this->_employees[$index]);
        echo "<p>{$e->getName()} has been removed from team {$this->getName()}.</p>";
    }
    function assignTask($task) {
        $this->tasks[] = $task;
        echo "<p>A new task has been assigned to team {$this->getName()}. It should be easy to do with {$this->getCount()} team member(s).</p>";
    }
     function completeTask($task) {
         $index = array_search($task, $this->tasks);
         unset($this->tasks[$index]);
         echo "<p>The '$task' task has been completed by team {$this->getName()}.</p>";
     }
    
    // Method for returning the number of team members:
    function getCount() {
        return count($this->_employees);
    }
    
} // End of Team class.

/* The Employee class extends WorkUnit.
 * The class has no new attributes or methods.
 */
class Employee extends WorkUnit {
    
    // Empty functions:
    function add(Employee $e) {
        return false;
    }
    function remove(Employee $e) {
        return false;
    }
        
    // Implement the abstract methods...
    function assignTask($task) {
        $this->tasks[] = $task;
        echo "<p>A new task has been assigned to {$this->getName()}. It will be done by {$this->getName()} alone.</p>";
    }
    function completeTask($task) {
        $index = array_search($task, $this->tasks);
        unset($this->tasks[$index]);
        echo "<p>The '$task' task has been completed by employee {$this->getName()}.</p>";
    }

} // End of Employee class.

Open in new window



<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Composite</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Using Composite</h2>
<?php # Script 7. 8.6 - composite.php
// This page uses the WorkUnit, Team, and Employee classes (Script 7. 8.5).

// Load the class definition:
require('WorkUnit.php');

// Create the objects:
$alpha = new Team('Alpha');
$john = new Employee('John');
$cynthia = new Employee('Cynthia');
$rashid = new Employee('Rashid');

// Assign employees to the team:
$alpha->add($john);
$alpha->add($rashid);

// Assign tasks:
$alpha->assignTask('Do something great.');
$cynthia->assignTask('Do something grand.');

// Complete a task:
$alpha->completeTask('Do something great.');

// Remove a team member:
$alpha->remove($john);

// Delete the objects:
unset($alpha, $john, $cynthia, $rashid);
?>
</body>
</html>

Open in new window



please explain all the type for local
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39931466
"Local" and "Elements" may have specific meanings in computer science, but it's not apparent from the question what meanings they would have in this context.  These terms are not present in the code snippets.  Can you please give us a better explanation of what you're looking for?  Thanks.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39931482
Ahh, now I see it.  The word "elements" appears in the picture.

It appears to refer to the properties of the object.  For example, the $e object is an instance of the Employee class, which inherits from WorkUnit.  The two "elements" it contains are an array named tasks (defined in WorkUnit) and a string named name containing the value "Rashid" assigned in line 20 of the second code snippet.
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 250 total points
ID: 39931663
greetings rgb192, I see you are still trying to learn about using objects in PHP.
Your question here is not about PHP, but about the "features" of the php programming text editor and code helper, maybe "nusphere phped".
In your what-are-elements.JPG  Image,  , , the "Code view" files are on the left view, you have the "workunit.php" in it in the image. You have the line selector in the "Team add" method of that php code file, , SO  your programming IDE automatically gives you a "View" in the right view of the code "structures-things" that are "executed" in the working code starting with -
$alpha = new Team('Alpha');

The "feature" in the right-view is suppose to tell you about some (not all) of the "code execution" for the Line selected  on the left, to HELP the developer (you) see some of what this add method is doing in code execution. No one can explain all of the right-view , because it will change every time the code section changes on the line selected in the left-view. Try and think of the right-view as an expanded php "var_dump" with info about this add method, and some of the assigned properties in the working code, , .

SO In this jpg image "line select" for right-view, it shows you that the $e in the method parameters add(Employee $e) is an object of Class Employee with two elements. In this IDE coding tags-references the "element" are things contained within that structure, in this case the object $e contains-holds 2 properties referred to as "elements" for "tasks" and "name" listed below.

If the code thing is an array such as _employees then the "elements" are not object properties but array elements that the array contains-holds, the 0 _employees-array element is an Object of Class Employee with two container elements.

if you were in left-view line selector for a "HTML thing" the the IDE elements would refer to any <div>, <b>, <span> that the "HTML thing" would contain-hold.

This is my help (guess) for this question, but it depends on the programming IDE not the language like PHP or javascript, or HTML
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39931718
If the code thing is an array such as _employees then the "elements" are not object properties...
I think the elements in this case are properties of the object.  They may be arrays instead of strings, but they are still properties.
0
 

Author Closing Comment

by:rgb192
ID: 39934699
thanks

I think the elements in this case are properties of the object.  They may be arrays instead of strings, but they are still properties.

Try and think of the right-view as an expanded php "var_dump" with info about this add method, and some of the assigned properties in the working code, , .
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question