Three class extended to one class [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I built this 4 classes where the Main is the one responsible for setting and getting the variables. I am using PHP7.1. Please let me know on how to make this more amazing or maybe using trait. How does my classes look? Is it professionally made? what do you guys think? thank you very much!
<?php
class Main
// Parameters
protected $first_name;
protected $middle_name;
protected $last_name;
public function first_name($first_name)
$this->first_name = $first_name;
return $this;
public function middle_name($middle_name)
$this->middle_name = $middle_name;
return $this;
public function last_name($last_name)
$this->last_name = $last_name;
return $this;
class Cpc extends Main
public function __construct()
echo 'this cpc construct <br>';
public function generateCpc()
echo 'this cpc generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Basetable extends Cpc
public function __construct()
echo 'this basetable construct <br>';
public function generateBasetable()
echo 'this basetable generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Layer extends Basetable
public function __construct()
echo 'this layer construct <br>';
public function generateLayer()
echo 'this layer generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Master extends Layer
public function __construct()
echo 'this Master construct <br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
$o = new Master();
$o->first_name('ken dan')->middle_name('sunico')->last_name('tinio')->generate();
?>
php object-oriented
closed as off-topic by Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel Jun 22 at 15:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel
add a comment |Â
up vote
0
down vote
favorite
I built this 4 classes where the Main is the one responsible for setting and getting the variables. I am using PHP7.1. Please let me know on how to make this more amazing or maybe using trait. How does my classes look? Is it professionally made? what do you guys think? thank you very much!
<?php
class Main
// Parameters
protected $first_name;
protected $middle_name;
protected $last_name;
public function first_name($first_name)
$this->first_name = $first_name;
return $this;
public function middle_name($middle_name)
$this->middle_name = $middle_name;
return $this;
public function last_name($last_name)
$this->last_name = $last_name;
return $this;
class Cpc extends Main
public function __construct()
echo 'this cpc construct <br>';
public function generateCpc()
echo 'this cpc generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Basetable extends Cpc
public function __construct()
echo 'this basetable construct <br>';
public function generateBasetable()
echo 'this basetable generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Layer extends Basetable
public function __construct()
echo 'this layer construct <br>';
public function generateLayer()
echo 'this layer generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Master extends Layer
public function __construct()
echo 'this Master construct <br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
$o = new Master();
$o->first_name('ken dan')->middle_name('sunico')->last_name('tinio')->generate();
?>
php object-oriented
closed as off-topic by Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel Jun 22 at 15:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel
1
It just occured to me that your question is off topic and will be closed. A code posted in the question is required to be a real one, not an imaginary sketch that does nothing practical.
â Your Common Sense
Jun 22 at 8:44
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I built this 4 classes where the Main is the one responsible for setting and getting the variables. I am using PHP7.1. Please let me know on how to make this more amazing or maybe using trait. How does my classes look? Is it professionally made? what do you guys think? thank you very much!
<?php
class Main
// Parameters
protected $first_name;
protected $middle_name;
protected $last_name;
public function first_name($first_name)
$this->first_name = $first_name;
return $this;
public function middle_name($middle_name)
$this->middle_name = $middle_name;
return $this;
public function last_name($last_name)
$this->last_name = $last_name;
return $this;
class Cpc extends Main
public function __construct()
echo 'this cpc construct <br>';
public function generateCpc()
echo 'this cpc generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Basetable extends Cpc
public function __construct()
echo 'this basetable construct <br>';
public function generateBasetable()
echo 'this basetable generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Layer extends Basetable
public function __construct()
echo 'this layer construct <br>';
public function generateLayer()
echo 'this layer generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Master extends Layer
public function __construct()
echo 'this Master construct <br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
$o = new Master();
$o->first_name('ken dan')->middle_name('sunico')->last_name('tinio')->generate();
?>
php object-oriented
I built this 4 classes where the Main is the one responsible for setting and getting the variables. I am using PHP7.1. Please let me know on how to make this more amazing or maybe using trait. How does my classes look? Is it professionally made? what do you guys think? thank you very much!
<?php
class Main
// Parameters
protected $first_name;
protected $middle_name;
protected $last_name;
public function first_name($first_name)
$this->first_name = $first_name;
return $this;
public function middle_name($middle_name)
$this->middle_name = $middle_name;
return $this;
public function last_name($last_name)
$this->last_name = $last_name;
return $this;
class Cpc extends Main
public function __construct()
echo 'this cpc construct <br>';
public function generateCpc()
echo 'this cpc generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Basetable extends Cpc
public function __construct()
echo 'this basetable construct <br>';
public function generateBasetable()
echo 'this basetable generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Layer extends Basetable
public function __construct()
echo 'this layer construct <br>';
public function generateLayer()
echo 'this layer generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
class Master extends Layer
public function __construct()
echo 'this Master construct <br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->first_name." ".$this->middle_name." ".$this->last_name;
echo '<br>';
$o = new Master();
$o->first_name('ken dan')->middle_name('sunico')->last_name('tinio')->generate();
?>
php object-oriented
asked Jun 22 at 6:45
ichimaru
33
33
closed as off-topic by Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel Jun 22 at 15:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel
closed as off-topic by Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel Jun 22 at 15:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Toby Speight, Billal BEGUERADJ, Stephen Rauch, Hosch250, Daniel
1
It just occured to me that your question is off topic and will be closed. A code posted in the question is required to be a real one, not an imaginary sketch that does nothing practical.
â Your Common Sense
Jun 22 at 8:44
add a comment |Â
1
It just occured to me that your question is off topic and will be closed. A code posted in the question is required to be a real one, not an imaginary sketch that does nothing practical.
â Your Common Sense
Jun 22 at 8:44
1
1
It just occured to me that your question is off topic and will be closed. A code posted in the question is required to be a real one, not an imaginary sketch that does nothing practical.
â Your Common Sense
Jun 22 at 8:44
It just occured to me that your question is off topic and will be closed. A code posted in the question is required to be a real one, not an imaginary sketch that does nothing practical.
â Your Common Sense
Jun 22 at 8:44
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Basically, this structure makes very little sense by itself, without knowing the real purpose of all these classes and the similarities worth extending.
But some suggestions could be made anyway.
- whatever class that is intended to display some data, by definition cannot have a property like first name. First names are generally belong to persons. A class must represent a solid entity, not a Frankenstein constructed from different parts. So in your place I would avoid creating such entities as cyborgs, that bear both human-like and machine-like features. Whatever belongs to a person, goes to one class, and whatever belongs to a table renderer belongs to another class.
- There is a PHP coding standard, and you are supposed to follow its guidelines.
So, for as little information as provided in your question, here is a class structure I propose for you:
There is a class Person that holds the person's personal information,
class Person
// Parameters
protected $firstName;
protected $middleName;
protected $lastName;
public function __construct($firstName, $middleName, $lastName)
$this->firstName = $firstName;
$this->middleName = $middleName;
$this->lastName = $lastName;
public function setFirstName($firstName)
$this->firstName = $firstName;
return $this;
public function setMiddleName($middleName)
$this->middleName = $middleName;
return $this;
public function setLastName($lastName)
$this->lastName = $lastName;
return $this;
public function getFirstName()
return $this->firstName;
public function getMiddleName()
return $this->middleName;
public function getLastName()
return $this->lastName;
and a class Output that renders tables.
class Output
protected $person;
public function __construct(Person $person)
echo 'this Master construct <br>';
$this->person = $person;
protected function generateCpc()
echo 'this cpc generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateBasetable()
echo 'this basetable generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateLayer()
echo 'this layer generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
so it can be used like this
$output = new Output(new Person('ken dan', 'sunico', 'tinio'));
$output->generate();
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Basically, this structure makes very little sense by itself, without knowing the real purpose of all these classes and the similarities worth extending.
But some suggestions could be made anyway.
- whatever class that is intended to display some data, by definition cannot have a property like first name. First names are generally belong to persons. A class must represent a solid entity, not a Frankenstein constructed from different parts. So in your place I would avoid creating such entities as cyborgs, that bear both human-like and machine-like features. Whatever belongs to a person, goes to one class, and whatever belongs to a table renderer belongs to another class.
- There is a PHP coding standard, and you are supposed to follow its guidelines.
So, for as little information as provided in your question, here is a class structure I propose for you:
There is a class Person that holds the person's personal information,
class Person
// Parameters
protected $firstName;
protected $middleName;
protected $lastName;
public function __construct($firstName, $middleName, $lastName)
$this->firstName = $firstName;
$this->middleName = $middleName;
$this->lastName = $lastName;
public function setFirstName($firstName)
$this->firstName = $firstName;
return $this;
public function setMiddleName($middleName)
$this->middleName = $middleName;
return $this;
public function setLastName($lastName)
$this->lastName = $lastName;
return $this;
public function getFirstName()
return $this->firstName;
public function getMiddleName()
return $this->middleName;
public function getLastName()
return $this->lastName;
and a class Output that renders tables.
class Output
protected $person;
public function __construct(Person $person)
echo 'this Master construct <br>';
$this->person = $person;
protected function generateCpc()
echo 'this cpc generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateBasetable()
echo 'this basetable generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateLayer()
echo 'this layer generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
so it can be used like this
$output = new Output(new Person('ken dan', 'sunico', 'tinio'));
$output->generate();
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
add a comment |Â
up vote
1
down vote
accepted
Basically, this structure makes very little sense by itself, without knowing the real purpose of all these classes and the similarities worth extending.
But some suggestions could be made anyway.
- whatever class that is intended to display some data, by definition cannot have a property like first name. First names are generally belong to persons. A class must represent a solid entity, not a Frankenstein constructed from different parts. So in your place I would avoid creating such entities as cyborgs, that bear both human-like and machine-like features. Whatever belongs to a person, goes to one class, and whatever belongs to a table renderer belongs to another class.
- There is a PHP coding standard, and you are supposed to follow its guidelines.
So, for as little information as provided in your question, here is a class structure I propose for you:
There is a class Person that holds the person's personal information,
class Person
// Parameters
protected $firstName;
protected $middleName;
protected $lastName;
public function __construct($firstName, $middleName, $lastName)
$this->firstName = $firstName;
$this->middleName = $middleName;
$this->lastName = $lastName;
public function setFirstName($firstName)
$this->firstName = $firstName;
return $this;
public function setMiddleName($middleName)
$this->middleName = $middleName;
return $this;
public function setLastName($lastName)
$this->lastName = $lastName;
return $this;
public function getFirstName()
return $this->firstName;
public function getMiddleName()
return $this->middleName;
public function getLastName()
return $this->lastName;
and a class Output that renders tables.
class Output
protected $person;
public function __construct(Person $person)
echo 'this Master construct <br>';
$this->person = $person;
protected function generateCpc()
echo 'this cpc generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateBasetable()
echo 'this basetable generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateLayer()
echo 'this layer generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
so it can be used like this
$output = new Output(new Person('ken dan', 'sunico', 'tinio'));
$output->generate();
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Basically, this structure makes very little sense by itself, without knowing the real purpose of all these classes and the similarities worth extending.
But some suggestions could be made anyway.
- whatever class that is intended to display some data, by definition cannot have a property like first name. First names are generally belong to persons. A class must represent a solid entity, not a Frankenstein constructed from different parts. So in your place I would avoid creating such entities as cyborgs, that bear both human-like and machine-like features. Whatever belongs to a person, goes to one class, and whatever belongs to a table renderer belongs to another class.
- There is a PHP coding standard, and you are supposed to follow its guidelines.
So, for as little information as provided in your question, here is a class structure I propose for you:
There is a class Person that holds the person's personal information,
class Person
// Parameters
protected $firstName;
protected $middleName;
protected $lastName;
public function __construct($firstName, $middleName, $lastName)
$this->firstName = $firstName;
$this->middleName = $middleName;
$this->lastName = $lastName;
public function setFirstName($firstName)
$this->firstName = $firstName;
return $this;
public function setMiddleName($middleName)
$this->middleName = $middleName;
return $this;
public function setLastName($lastName)
$this->lastName = $lastName;
return $this;
public function getFirstName()
return $this->firstName;
public function getMiddleName()
return $this->middleName;
public function getLastName()
return $this->lastName;
and a class Output that renders tables.
class Output
protected $person;
public function __construct(Person $person)
echo 'this Master construct <br>';
$this->person = $person;
protected function generateCpc()
echo 'this cpc generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateBasetable()
echo 'this basetable generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateLayer()
echo 'this layer generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
so it can be used like this
$output = new Output(new Person('ken dan', 'sunico', 'tinio'));
$output->generate();
Basically, this structure makes very little sense by itself, without knowing the real purpose of all these classes and the similarities worth extending.
But some suggestions could be made anyway.
- whatever class that is intended to display some data, by definition cannot have a property like first name. First names are generally belong to persons. A class must represent a solid entity, not a Frankenstein constructed from different parts. So in your place I would avoid creating such entities as cyborgs, that bear both human-like and machine-like features. Whatever belongs to a person, goes to one class, and whatever belongs to a table renderer belongs to another class.
- There is a PHP coding standard, and you are supposed to follow its guidelines.
So, for as little information as provided in your question, here is a class structure I propose for you:
There is a class Person that holds the person's personal information,
class Person
// Parameters
protected $firstName;
protected $middleName;
protected $lastName;
public function __construct($firstName, $middleName, $lastName)
$this->firstName = $firstName;
$this->middleName = $middleName;
$this->lastName = $lastName;
public function setFirstName($firstName)
$this->firstName = $firstName;
return $this;
public function setMiddleName($middleName)
$this->middleName = $middleName;
return $this;
public function setLastName($lastName)
$this->lastName = $lastName;
return $this;
public function getFirstName()
return $this->firstName;
public function getMiddleName()
return $this->middleName;
public function getLastName()
return $this->lastName;
and a class Output that renders tables.
class Output
protected $person;
public function __construct(Person $person)
echo 'this Master construct <br>';
$this->person = $person;
protected function generateCpc()
echo 'this cpc generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateBasetable()
echo 'this basetable generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
protected function generateLayer()
echo 'this layer generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
public function generate()
$this->generateCpc();
$this->generateBasetable();
$this->generateLayer();
echo 'this master generated <br>';
echo $this->person->getFirstName()." ".$this->person->getMiddleName()." ".$this->person->getLlast_name;
echo '<br>';
so it can be used like this
$output = new Output(new Person('ken dan', 'sunico', 'tinio'));
$output->generate();
answered Jun 22 at 8:40
Your Common Sense
2,405523
2,405523
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
add a comment |Â
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
Also a good point that your structure separates data from output (model vs view)
â TimSparrow
Jun 22 at 9:59
add a comment |Â
1
It just occured to me that your question is off topic and will be closed. A code posted in the question is required to be a real one, not an imaginary sketch that does nothing practical.
â Your Common Sense
Jun 22 at 8:44