Three class extended to one class [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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();

?>






share|improve this question











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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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
















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();

?>






share|improve this question











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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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












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();

?>






share|improve this question











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();

?>








share|improve this question










share|improve this question




share|improve this question









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
If this question can be reworded to fit the rules in the help center, please edit the question.




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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 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




    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










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();





share|improve this answer





















  • Also a good point that your structure separates data from output (model vs view)
    – TimSparrow
    Jun 22 at 9:59

















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();





share|improve this answer





















  • Also a good point that your structure separates data from output (model vs view)
    – TimSparrow
    Jun 22 at 9:59














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();





share|improve this answer





















  • Also a good point that your structure separates data from output (model vs view)
    – TimSparrow
    Jun 22 at 9:59












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();





share|improve this answer













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();






share|improve this answer













share|improve this answer



share|improve this answer











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
















  • 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


Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation