Skip to content

Instantly share code, notes, and snippets.

@lbattaglioli2000
Last active February 20, 2020 21:53
Show Gist options
  • Save lbattaglioli2000/9edcf5fff765cba3377df2aa5fe077ea to your computer and use it in GitHub Desktop.
Save lbattaglioli2000/9edcf5fff765cba3377df2aa5fe077ea to your computer and use it in GitHub Desktop.

Registration Re-Design Proposal

When an event is created, there needs to be the ability to add various Addon objects to that Event object. There will need to be various types of Addon's that we can create, which will be create-able from the admin panel.

The Addon Interface

The Addon interface will act as a "contract" so to speak. It will define the basic methods that are needed for an object to be considered an Addon while leaving the actual implementation/functionality ambiguous, and tentative for each implementation of the Addon interface.

The Addon interface will have several methods, and I thought these were the most appropriate:

/**
 * Get the price of the Addon.
 *
 * @return int
 */
public function getPriceAttribute();

/**
 * Get the description of the Addon.
 *
 * @return string
 */
public function getDescriptionAttribute();

/**
 * Get any custom modifiers of the Addon.
 * 
 * @return array
 */
public function getModifiersAttribute();

TShirt implements Addon

The first Addon subclass would be TShirt. It'd look something like this:

public class TShirt extends Model implements Addon
{
  public function registration()
	{
		return $this->belongsTo(Registration::class);
	}
	
	public function getPriceAttribute()
	{
		return $this->price;
	}
	
	public function getDescriptionAttribute()
	{
		return $this->description;
	}
	
	public function getModifiersAttribute()
	{
		return $this->modifiers;
	}
	
	public function getSizeAttribute()
	{
		return $this->size;
	}
}

Bracelet implements Addon

The next Addon subclass would be Bracelet. It'd look something like this:

public class Bracelet extends Model implements Addon
{
	public function registration()
	{
		return $this->belongsTo(Registration::class);
	}
	
	public function getPriceAttribute()
	{
		return $this->price;
	}
	
	public function getDescriptionAttribute()
	{
		return $this->description;
	}
	
	public function getModifiersAttribute()
	{
		return $this->modifiers;
	}
	
	// Maybe? I'm not sure what the bracelets are...
	public function getColorAttribute()
	{
		return $this->color;
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment