PPT generator using SOLID principles

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
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?







share|improve this question



























    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?







    share|improve this question























      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?







      share|improve this question













      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?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 20 at 18:33









      Phrancis

      14.6k644137




      14.6k644137









      asked Jun 20 at 18:15









      Edson Horacio Junior

      1236




      1236




















          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.






          share|improve this answer





















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "196"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            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






























            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.






            share|improve this answer

























              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.






              share|improve this answer























                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.






                share|improve this answer













                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.







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jun 20 at 18:18









                TurqSpl

                1562




                1562






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    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













































































                    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