In PHP, you can have a collection as an array as a class property. This collection can have a function add
that takes multiple (type-hinted) parameters, as such: add( Markup $markup, Style $style = Null)
, the keyword here is Null
, the system tells you that "hey, you don't have to add this, but you can do it, but it has to be of type Style
)" and adds a package to that internal array:
public function add( $name, Markup $markup, Style $style = Null )
{
$this->packages[$name]['markup'] = $markup;
if( $style ) {
$this->packages[$name]['style'] = $style;
}
}
Which means that 100% a package has a markup
object, but it can have a style
as well.
Thing is - watch what happens when, by good intentions, I just wanna have things separated such that my interfaces aren't cluttered:
public function add( $name, Markup $markup, Style $style = Null, Categorized $categories, .. )
{
$this->packages[$name]['markup'] = $markup;
if( $style ) {
$this->packages[$name]['style] = $style;
}
if( $categories ) {
$this->packages[$name]['categories'] = $categories;
}
//.. and so on, gets cluttered.
}
This ramps up to be Satan-level hectic to maintain.
What is a solution to this?