Chain-of-responsibility pattern and composition

Sorry for my ignorance but I am little bit confused about Chain-of-responsibility pattern and composition. Below is my code,

class ValidatorChain {      private $  validators;     public function __construct(IValidator ...$  validators)     {         $  this->validators = $  validators;     }      public function isValid(Argument $  arg): bool     {         foreach ($  this->validators as $  validator) {             if (!$  validator->isValid($  arg)) {                 return false;             };         }         return true;     } } 

What I needed is to keep multiple validation in one class and loop all the validations? Can you please suggest to improve the above code(including class name)? Can we call it Chain-of-responsibility pattern or it has any separate design name?

Loop Refactoring C# Unity

So I started learning OOs and code refactoring and decided to do some project. It just some simple quiz game.

Here are some mechanics

  • There are 3 sets

  • Each set have 8 Brands (types)

  • Each brand have 10 questions

So what I did was this

Set Class

public class Set{     public string setName;     public Brand[] brands; } 

Brand Class

public class Brand{     public string brandName;     public Question[] questions; } 

Question Class

public class Question {     public string question;     public string[] choices = new string[3];  //choices for each question     public string correctAnswer;  //will hold the correct answer for a question      public string questionID(){        // making a id for question         string qID = "";          qID += question + "|";          foreach(string choice in choices){             qID += choice + "|";         }          qID += correctAnswer + "|";          qID += fontSize;          return qID;     }  } 

So what I need is to create some kind of id for each question, what I did is this

public class QuestionManager : MonoBehaviour { public void saveToDB(){     int setID = 0;       foreach(Set set in sets){            int brandID = 0;           foreach(Brand brand in set.brands){                int questionID = 0;               foreach(Question question in brand.questions){                       string questionKey = "s" + setID + "|" + "b" + brandID + "|" + "q" + questionID;                }             brandID++;           }           setID++;       }  } } 

I’m really curious if there are some good refactoring for this kind of loop. Also I should add that I’ll be using this ids for getting the questions later.

办埃克塞特大学毕业证成绩单Q薇501058216【仿真英国文凭】修改成绩单造假英国本科学历/英国硕士学历代办英国学位证书|英国留信认证|英国使馆认证|教育部认证|国内真实可查存档The Unive


办埃克塞特大学毕业证成绩单Q薇501058216【仿真英国文凭】修改成绩单造假英国本科学历/英国硕士学历代办英国学位证书|英国留信认证|英国使馆认证|教育部认证|国内真实可查存档The Unive

CSS Help

Hello all,

I have recently started coding and have found myself to be good at HTML but CSS I struggle. If anybody would be able to help me… | Read the rest of

Best way of writing PHP, progressing & acquiring simple inputs & outputs

As my first simple PHP project, I’ve created a simple project that allows you to just enter your name and two numbers, where it displays them on the page and stores them in a database. It consists of 3 files: index.php, db.php & process.php. I wonder whether I have created the code efficiently.

I’m curious about all the talk behind procedural PHP vs PDO. I initially used some deprecated PHP5 functions and was corrected by the stack overflow community, but this has left me confused as to what specifically I should learn with PHP as a beginner. It sounds like procedural and PDO are very different, and that I should only pick one and learn that.

So my questions are as follows:

  1. Is the coding in my project acceptable?
  2. Is it similar to how most PHP projects are built? (i.e. are most procedural or PDO)
  3. What should I learn as a beginner? (procedural or PDO?)
  4. Do you have any beginner advice?

Any advice here would be very much appreciated as I’m new to PHP. Thanks for any help here. The files and code (excluding HTML & CSS) are below:


<?php include 'db.php'; ?>  <?php // Fetch data from db $  query = mysqli_query($  con, 'SELECT * FROM data'); ?>  <!-- create a loop (while there are results in the DB, spit them out) -->             <?php while ($  row = $  query->fetch_assoc()) : ?>                 <li><?php echo $  row['t_name'] ?> entered <?php echo $  row['t_firstNo'] ?> and <?php echo $  row['t_secondNo'] ?> (result =                      <?php                         $  first = $  row['t_firstNo'];                         $  second = $  row['t_secondNo'];                         $  result = $  first * $  second;                         echo $  result;                     ?>)</li>             <?php endwhile ?>  <!-- if bad input, get & display error -->             <?php if(isset($  _GET['error'])) : // if error variable is there ?>                 <?php echo $  _GET['error']; // get the error ?>             <?php endif ?> 


<?php  // Connect $  con = mysqli_connect("localhost", "tnnick", "PHPprojects", "timesNumbers");  // Test Connection if (mysqli_connect_errno()) {     echo 'Failed: '.mysqli_connect_error(); }  ?> 


<?php include 'db.php' ; ?>  <?php     if(isset($  _POST['submit'])) { // if form submitted         $  nickname = mysqli_real_escape_string($  con, $  _POST['nickname']); // get the inputs         $  firstNo = mysqli_real_escape_string($  con, $  _POST['firstNo']);         $  secondNo = mysqli_real_escape_string($  con, $  _POST['secondNo']);     } ?>  <?php // validate inputs if(!isset($  nickname) || $  nickname=='' || !isset($  firstNo) || $  firstNo=='' || !isset($  secondNo) || $  secondNo=='' ) {     // if invalid input, send error to index.php     $  error = 'Bad input - try again.'; // create error message     header("Location: index.php?error=".urlencode($  error)); // attach to URL & send to index.php     exit(); } else {     // insert into DB     $  putIntoDB = "INSERT INTO data (t_name, t_firstNo, t_secondNo) VALUES ('$  nickname','$  firstNo','$  secondNo')";      // check it inserted     if(!mysqli_query($  con, $  putIntoDB)) {         die('Error');     } else {         header("Location: index.php");         exit();     } } ?>