PPT generator using SOLID principles
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
I want to use SOLID more and more but still learning, I'm improving a PPT generator and would like your help applying SOLID principles in it.
- That generator should print two photos per slide, first one to the left, second to the right;
- If the last photo is a left photo, it should be placed in center;
- Each photo has a text right below it;
- I'll use a third party PPT lib to do the low level stuff.
This is what I came up with, a little bit abstracted just to pass the idea, the sample is in PHP but I'll accept answers in any programming language:
class Controller
$ppt = new Ppt(Ppt::DEFAULT_RESOLUTION, $background, $header, $footer);
$ppt->writeSlides($photoCollection);
$pptFile = $ppt->saveToFile();
$ppt->deleteLocalTemporaryFiles();
readfile($pptFile);
unlink($pptFile);
class Ppt extends thirdPartyPptLib
const DEFAULT_RESOLUTION = 'x';
private $resolution;
private $background;
private $header;
private $footer;
public function __construct($resolution = null, $background = null, $header = null, $footer = null)
$this->resolution = $resolution;
$this->background = $background;
$this->header = $header;
$this->footer = $footer;
public function writeSlides(Traversable $photoCollection)
$i = 0;
$count = count($photoCollection);
foreach ($photoCollection as $photoInfo)
$photoToLeft = $i % 2 == 0;
$isLastPhoto = $i == ($count - 1);
if ($isLastPhoto)
$slide = $this->newSlide();
$slide->addCenterPhotoInfo($photoInfo);
else if ($photoToLeft)
$slide = $this->newSlide();
$slide->addLeftPhotoInfo($photoInfo);
else
$slide->addRightPhotoInfo($photoInfo);
$i++;
private function newSlide()
$slide = parent->newSlide();
if ($this->hasBackground())
$slide->setBackground();
if ($this->hasHeader())
$slide->setHeader();
if ($this->hasFooter())
$slide->setFooter();
return $slide;
class Slide extends thirdPartyPptLibSlide
public function addLeftPhotoInfo($photoInfo)
$this->addLeftPhoto($photoInfo->getPhoto());
$this->addUnderlyingText($photoInfo->getText());
// functions addRightPhotoInfo and addCenterPhotoInfo very similar
Should I separate it more into different classes? Or methods? Should I create Interfaces?
php object-oriented
add a comment |Â
up vote
3
down vote
favorite
I want to use SOLID more and more but still learning, I'm improving a PPT generator and would like your help applying SOLID principles in it.
- That generator should print two photos per slide, first one to the left, second to the right;
- If the last photo is a left photo, it should be placed in center;
- Each photo has a text right below it;
- I'll use a third party PPT lib to do the low level stuff.
This is what I came up with, a little bit abstracted just to pass the idea, the sample is in PHP but I'll accept answers in any programming language:
class Controller
$ppt = new Ppt(Ppt::DEFAULT_RESOLUTION, $background, $header, $footer);
$ppt->writeSlides($photoCollection);
$pptFile = $ppt->saveToFile();
$ppt->deleteLocalTemporaryFiles();
readfile($pptFile);
unlink($pptFile);
class Ppt extends thirdPartyPptLib
const DEFAULT_RESOLUTION = 'x';
private $resolution;
private $background;
private $header;
private $footer;
public function __construct($resolution = null, $background = null, $header = null, $footer = null)
$this->resolution = $resolution;
$this->background = $background;
$this->header = $header;
$this->footer = $footer;
public function writeSlides(Traversable $photoCollection)
$i = 0;
$count = count($photoCollection);
foreach ($photoCollection as $photoInfo)
$photoToLeft = $i % 2 == 0;
$isLastPhoto = $i == ($count - 1);
if ($isLastPhoto)
$slide = $this->newSlide();
$slide->addCenterPhotoInfo($photoInfo);
else if ($photoToLeft)
$slide = $this->newSlide();
$slide->addLeftPhotoInfo($photoInfo);
else
$slide->addRightPhotoInfo($photoInfo);
$i++;
private function newSlide()
$slide = parent->newSlide();
if ($this->hasBackground())
$slide->setBackground();
if ($this->hasHeader())
$slide->setHeader();
if ($this->hasFooter())
$slide->setFooter();
return $slide;
class Slide extends thirdPartyPptLibSlide
public function addLeftPhotoInfo($photoInfo)
$this->addLeftPhoto($photoInfo->getPhoto());
$this->addUnderlyingText($photoInfo->getText());
// functions addRightPhotoInfo and addCenterPhotoInfo very similar
Should I separate it more into different classes? Or methods? Should I create Interfaces?
php object-oriented
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I want to use SOLID more and more but still learning, I'm improving a PPT generator and would like your help applying SOLID principles in it.
- That generator should print two photos per slide, first one to the left, second to the right;
- If the last photo is a left photo, it should be placed in center;
- Each photo has a text right below it;
- I'll use a third party PPT lib to do the low level stuff.
This is what I came up with, a little bit abstracted just to pass the idea, the sample is in PHP but I'll accept answers in any programming language:
class Controller
$ppt = new Ppt(Ppt::DEFAULT_RESOLUTION, $background, $header, $footer);
$ppt->writeSlides($photoCollection);
$pptFile = $ppt->saveToFile();
$ppt->deleteLocalTemporaryFiles();
readfile($pptFile);
unlink($pptFile);
class Ppt extends thirdPartyPptLib
const DEFAULT_RESOLUTION = 'x';
private $resolution;
private $background;
private $header;
private $footer;
public function __construct($resolution = null, $background = null, $header = null, $footer = null)
$this->resolution = $resolution;
$this->background = $background;
$this->header = $header;
$this->footer = $footer;
public function writeSlides(Traversable $photoCollection)
$i = 0;
$count = count($photoCollection);
foreach ($photoCollection as $photoInfo)
$photoToLeft = $i % 2 == 0;
$isLastPhoto = $i == ($count - 1);
if ($isLastPhoto)
$slide = $this->newSlide();
$slide->addCenterPhotoInfo($photoInfo);
else if ($photoToLeft)
$slide = $this->newSlide();
$slide->addLeftPhotoInfo($photoInfo);
else
$slide->addRightPhotoInfo($photoInfo);
$i++;
private function newSlide()
$slide = parent->newSlide();
if ($this->hasBackground())
$slide->setBackground();
if ($this->hasHeader())
$slide->setHeader();
if ($this->hasFooter())
$slide->setFooter();
return $slide;
class Slide extends thirdPartyPptLibSlide
public function addLeftPhotoInfo($photoInfo)
$this->addLeftPhoto($photoInfo->getPhoto());
$this->addUnderlyingText($photoInfo->getText());
// functions addRightPhotoInfo and addCenterPhotoInfo very similar
Should I separate it more into different classes? Or methods? Should I create Interfaces?
php object-oriented
I want to use SOLID more and more but still learning, I'm improving a PPT generator and would like your help applying SOLID principles in it.
- That generator should print two photos per slide, first one to the left, second to the right;
- If the last photo is a left photo, it should be placed in center;
- Each photo has a text right below it;
- I'll use a third party PPT lib to do the low level stuff.
This is what I came up with, a little bit abstracted just to pass the idea, the sample is in PHP but I'll accept answers in any programming language:
class Controller
$ppt = new Ppt(Ppt::DEFAULT_RESOLUTION, $background, $header, $footer);
$ppt->writeSlides($photoCollection);
$pptFile = $ppt->saveToFile();
$ppt->deleteLocalTemporaryFiles();
readfile($pptFile);
unlink($pptFile);
class Ppt extends thirdPartyPptLib
const DEFAULT_RESOLUTION = 'x';
private $resolution;
private $background;
private $header;
private $footer;
public function __construct($resolution = null, $background = null, $header = null, $footer = null)
$this->resolution = $resolution;
$this->background = $background;
$this->header = $header;
$this->footer = $footer;
public function writeSlides(Traversable $photoCollection)
$i = 0;
$count = count($photoCollection);
foreach ($photoCollection as $photoInfo)
$photoToLeft = $i % 2 == 0;
$isLastPhoto = $i == ($count - 1);
if ($isLastPhoto)
$slide = $this->newSlide();
$slide->addCenterPhotoInfo($photoInfo);
else if ($photoToLeft)
$slide = $this->newSlide();
$slide->addLeftPhotoInfo($photoInfo);
else
$slide->addRightPhotoInfo($photoInfo);
$i++;
private function newSlide()
$slide = parent->newSlide();
if ($this->hasBackground())
$slide->setBackground();
if ($this->hasHeader())
$slide->setHeader();
if ($this->hasFooter())
$slide->setFooter();
return $slide;
class Slide extends thirdPartyPptLibSlide
public function addLeftPhotoInfo($photoInfo)
$this->addLeftPhoto($photoInfo->getPhoto());
$this->addUnderlyingText($photoInfo->getText());
// functions addRightPhotoInfo and addCenterPhotoInfo very similar
Should I separate it more into different classes? Or methods? Should I create Interfaces?
php object-oriented
edited Jun 20 at 18:33
Phrancis
14.6k644137
14.6k644137
asked Jun 20 at 18:15
Edson Horacio Junior
1236
1236
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
You can remove the overloading of properties from constructor.
This way you can improve the code maintaning and readability.
An example of improvement:
class Style
// Properties here
class Ppt
public function __construct(Style $style)
Now you pass just the object of style with all the needed properties.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
You can remove the overloading of properties from constructor.
This way you can improve the code maintaning and readability.
An example of improvement:
class Style
// Properties here
class Ppt
public function __construct(Style $style)
Now you pass just the object of style with all the needed properties.
add a comment |Â
up vote
4
down vote
accepted
You can remove the overloading of properties from constructor.
This way you can improve the code maintaning and readability.
An example of improvement:
class Style
// Properties here
class Ppt
public function __construct(Style $style)
Now you pass just the object of style with all the needed properties.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
You can remove the overloading of properties from constructor.
This way you can improve the code maintaning and readability.
An example of improvement:
class Style
// Properties here
class Ppt
public function __construct(Style $style)
Now you pass just the object of style with all the needed properties.
You can remove the overloading of properties from constructor.
This way you can improve the code maintaning and readability.
An example of improvement:
class Style
// Properties here
class Ppt
public function __construct(Style $style)
Now you pass just the object of style with all the needed properties.
answered Jun 20 at 18:18
TurqSpl
1562
1562
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196910%2fppt-generator-using-solid-principles%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password