A color class and a CRUD class for it Is it better to have only one class color and include the functions from the second class in the 1st one? Or leave them apart?

Why is one better than the other or vice versa? The design pattern is important to me, so why choose one over the other?

Is there a problem if, let's say, we have the function create_color in which we instantiate the class itself like new color()?

class color
{
private $id = NULL; 
private $name = '';
private $rgb = NULL; 
private $cmy = NULL;
private $wavelength = NULL; 
private $frequency = NULL; 

public function __construct($name, $rgb, $cmy, $wavelenght, $frequency)
{
setName($name);
setRGB($rgb);
setCMY($cmy);
setWavelength($wavelength);
setFrequency($frequency);
}

public function __destruct()
{
}

public function setName($name)
{
$this-&gt;name=$name;
}

public function setRGB($rgb)
{
$this-&gt;rgb=$rgb;
}

public function setCMY($cmy)
{
$this-&gt;cmy=$cmy;
}

public function setWavelength($wavelength)
{
$this-&gt;wavelength=$wavelength;
}

public function setFrequency($frequency)
{
$this-&gt;frequency=$frequency;
}

public function getId()
{
return $this-&gt;id;
}

public function getName()
{
return $this-&gt;name;
}

public function getRGB()
{
return $this-&gt;rgb;
}

public function getCMY()
{
return $this-&gt;cmy;
}

public function getWavelength()
{
return $this-&gt;wavelength;
}

public function getFrequency()
{
return $this-&gt;frequency;
}

public function toJSON()
{
return "{'id':'".$this-&gt;id."', 'name':'".$this-&gt;name."', 'rgb':'".$this-&gt;rgb."', 'cmy':'".$this-&gt;cmy."', 'wavelength':'".$this-&gt;wavelength."', 'frequency':'".$this-&gt;frequency."'}";
}

public function toCSV()
{
return $this-&gt;id . ", " . $this-&gt;name . ", " . $this-&gt;rgb . ", " . $this-&gt;cmy . ", " . $this-&gt;wavelength . ", " . $this-&gt;frequency;
}

public function toHTML()
{
return "&lt;p&gt;ID: " . $this-&gt;id . "&lt;/p&gt;&lt;p&gt;Name: " . $this-&gt;name . "&lt;/p&gt;&lt;p&gt;RGB: " . $this-&gt;rgb . "&lt;/p&gt;&lt;p&gt;CMY: " . $this-&gt;cmy . "&lt;/p&gt;&lt;p&gt;Wavelength: " . $this-&gt;wavelength . "&lt;/p&gt;&lt;p&gt;Frequency: " . $this-&gt;frequency . "&lt;/p&gt;";
}
}


Second class:

class CRUD_color
{
public function create_color($parameters)
{
   $color=new color();
   $color-&gt;setName($parameter['name']);
   $color-&gt;setRGB($parameter['rgb']);
   $color-&gt;setCMY($parameter['cmy']);
   $color-&gt;setWavelength($parameter['wavelength']);
   $color-&gt;setFrequency($parameter['frequency']);

   $entitymanager-&gt;persist($color);
   $entitymanager-&gt;flush();
}
public function request_color($parameters)
{
   $color=$entitymanager-&gt;find($parameter['id']);
   echo $color-&gt;toJSON($parameter['name']);
}
public function update_color($parameters)
{
   $color=$entitymanager-&gt;find($parameter['id']);
   $color-&gt;setName($parameter['name']);
   $color-&gt;setRGB($parameter['rgb']);
   $color-&gt;setCMY($parameter['cmy']);
   $color-&gt;setWavelength($parameter['wavelength']);
   $color-&gt;setFrequency($parameter['frequency']);

   $entitymanager-&gt;persist($color);
   $entitymanager-&gt;flush();
}
public function delete_color($parameters)
{
   $color=$entitymanager-&gt;delete($parameter['id']);
}
}
Just from looking at both classes, CRUD_color is essentially putting methods on top of Color but those methods seem like something you'd want in Color. I would ask yourself what the purpose CRUD_color serves that Color should not. If there is no reason for the 2nd class, then get rid of it.

I would recommend overloading the __get() operator and get rid of the get methods, it'll clean things up a little bit in your first class.

Also I wouldn't have create_color accept an array of parameters, instead be explicit with what the values need. If you don't want to take this advice, then at least do some error checking for when those parameters don't exist in the array.

...Also I think CRUD_color should probably be static, or at least right now it seems like you are treating it as a static class. If you want it to act like a class which is inheriting from Color I would instead have a constructor and initialize a Color object which is a data-member of CRUD_color.