fundacja tvn joomla-cms.com.pl
A+ A A-

Special Arguments

  • Kategoria: Class
  • Opublikowano: piątek, 13, grudzień 2013 12:28
  • Super User
  • Odsłony: 38700

Special Arguments

 

Chciałem wam przedstawić dość ciekawą klasę, z mojego punktu widzenia,która może rozwiązać problem przekazywania argumentów poprzez konstruktor.Jeżeli nie wiemy ile parametrów będziemy przekazywać do konstruktora możemy zrobić to w ten sposób.Nie musimy ingerować w samą klasę za każdym razem kiedy dopisujemy kolejny parametr.Załóżmy że mamy samochód w którym nie wiemy ile osób będzie podróżować,a chcemy przekazać do konstruktora, za każdym razem inną ilość osób.

 
* Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0 * 
* Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. If you do not know how many parameters we pass to the constructor, we can do it this way. We do not need to interfere in the same class each time when we add another parameter. Suppose that we have a car that does not know how many people will travel and we want to pass to the constructor, each time a different number of people. Are we about contained in the class rules say that it is a new design pattern Special Arguments. Please send your feedback by email  Jeżeli nie wiemy ile parametrów będziemy przekazywali do konstruktora możemy zrobić to w ten sposób. Nie musimy ingerować w samą klasę za każdym razem kiedy dopisujemy kolejny parametr. Zakładamy że mamy samochód w którym nie wiemy ile osób będzie podróżować, a chcemy przekazać do konstruktora, za każdym razem inną ilość osób. Czy możemy o zawartych w klasie regułach‚ach powiedzieć, że jest to nowy wzorzec projektowy Special Arguments. Prześlijcie wasze opinie na email  co o tym sądzicie. */

 class special_arguments{
 public $person = array();
 public function __construct(){ 
if($arg = func_num_args()>0){
 $this->person = func_get_args(); 
} }
 public function car(){
 return $this->person; } } 
$adam = "1 person";
 $ginter = "2 person";
 $bodzio = "3 person"; 
$endriu = "4 person";
 $bandzo = "5 person";
 $test = new special_arguments($adam, $ginter, $bodzio, $endriu, $bandzo);
 $a = $test->car();
 foreach($a as $person){ 
echo $person.""; }
 

 
* Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0 
* * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. If you do not know how many parameters we pass to the constructor, we can do it this way. We do not need to interfere in the same class each time when we add another parameter. Suppose that we have a car that does not know how many people will travel and we want to pass to the constructor, each time a different number of people. Are we about contained in the class rules say that it is a new design pattern Special Arguments. Please send your feedback by email  

class special_arguments{ 
public $person = array();
 public function __construct(){
 if($arg = func_num_args()>0){
 $this->person = func_get_args(); 
} }
 public function person1(){
 return $this->person["a"];
 }
 public function person2(){
 return $this->person["b"];
 } 
public function person3(){
 return $this->person["c"]; 
} 
public function person4(){ 
return $this->person["d"]; 
} 
public function person5(){
 return $this->person["e"]; 
} } 

## Wywołanie w pliku ## $adam = "1 person"; $ginter = "2 person";
 $bodzio = "3 person"; $endriu = "4 person"; $bandzo = "5 person";
 ## Special Arguments ##
 ## Możemy dowolnie zmieniać na te metody które chcemy ## 
$test = new special_arguments(array("a"=>$adam, "b"=>$ginter, "c"=>$bodzio, "d"=>$endriu, "e"=>$bandzo)); 
## albo ## $test = new special_arguments(array( "b"=>$ginter, "d"=>$endriu, "e"=>$bandzo));
 ## albo ## $test = new special_arguments(array("a"=>$adam, "e"=>$bandzo));
 foreach($test->person[0] as $person){
 echo $person.""; }
 

   
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
 
    If you do not know how many parameters we pass to the constructor, we can do it this way.
    We do not need to interfere in the same class each time when we add another parameter.
    Suppose that we have a car that does not know how many people will travel
    and we want to pass to the constructor, each time a different number of people.
    Are we about contained in the class rules say that it is a new design pattern Special Arguments.
    Please send your feedback by email 
    */

  abstract class person1{
        public static function person11(){
        return "person 1";
     }
  }
 
  abstract class person2{
        public static function person22(){
        return "person 2";
     }
  }

  abstract class person3{
        public static function person33(){
        return "person 3";
     }
  }
 
  abstract class person4{
        public static function person44(){
        return "person 4";
     }
  }
 
  abstract class person5{
        public static function person55(){
        return "person 5";
     }
  }
 
    class special_arguments{
       public $person = array();
     
    public function __construct(){
      if($arg = func_num_args()>0){
         $this->person = func_get_args();
      }
     }
     
     public function person1(){
        return $this->person["a"];
     }
    
     public function person2(){
        return $this->person["b"];
     }
    
     public function person3(){
        return $this->person["c"];
     }
    
     public function person4(){
        return $this->person["d"];
     }
    
     public function person5(){
        return $this->person["e"];
     }
    }
         
           ## Special Arguments ##
           ## Możemy dowolnie zmieniać na te klasy które chcemy ##
            //$test = new special_arguments(array("a"=>person1::person11(), "b"=>person2::person22(), "c"=>person3::person33(), "d"=>person4::person44(), "e"=>person5::person55()));
                   ## albo ##
            //$test = new special_arguments(array( "b"=>person2::person22(), "d"=>person4::person44(), "e"=>person5::person55()));
                   ## albo ##
            $test = new special_arguments(array("a"=>person1::person11(), "e"=>person5::person55()));
 
        foreach($test->person[0] as $person){
           echo $person."
";
      }

 

 
 
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
 
    If you do not know how many parameters we pass to the constructor, we can do it this way.
    We do not need to interfere in the same class each time when we add another parameter.
    Suppose that we have a car that does not know how many people will travel
    and we want to pass to the constructor, each time a different number of people.
    Are we about contained in the class rules say that it is a new design pattern Special Arguments.
    Please send your feedback by email 
*/

   class person11{
        public function person11(){
        return "person 1";
     }
    
     public function person12(){
        return "person 1 i 2";
     }
  }
 
   class person22{
        public function person22(){
        return "person 2";
     }
  }

   class person33{
        public function person33(){
        return "person 3";
     }
  }
 
   class person44{
        public function person44(){
        return "person 4";
     }
  }
 
   class person55{
        public function person55(){
        return "person 5";
     }
  }
 
    class special_arguments{
       public $person = array();
     
    public function __construct(){
      if($arg = func_num_args()>0){
         $this->person = func_get_args();
      }
     }
     
     public function person1(){
        return $this->person[0]["a"];
     }
    
     public function person2(){
        return $this->person[0]["b"];
     }
    
     public function person3(){
        return $this->person[0]["c"];
     }
    
     public function person4(){
        return $this->person[0]["d"];
     }
    
     public function person5(){
        return $this->person[0]["e"];
     }
    }
         
           ## Special Arguments ##
           ## Możemy dowolnie zmieniać na te klasy które chcemy ##
            //$test = new special_arguments(array("a"=>new person11(), "b"=>new person22(), "c"=>new person33(), "d"=>new person44(), "e"=>new person55()));
                   ## albo ##
            //$test = new special_arguments(array( "b"=>new person22(), "d"=>new person44(), "e"=>new person55()));
                   ## albo ##
            $test = new special_arguments(array("a"=>new person11(), "e"=>new person55()));
 
        echo $test->person1()->person11();
        echo "
";
        echo $test->person1()->person12();
        echo "
";
        echo $test->person5()->person55(); 

Komentarze  

 
+1 #3 lansing social 2014-07-09 22:57
Thanks for sharing such a nice opinion, article is good, thats why i have read it completely
Cytować
 
 
+1 #2 boker 2013-12-18 22:30
:lol:
Cytować
 
 
+1 #1 Orbit 2013-12-18 22:29
calkiem niezle
Cytować
 

Dodaj komentarz


Kod antyspamowy
Odśwież

 Pozycjonowanie-Joomla, seo-joomla Tworzenie-Sitemap-joomla, TG-Chmura-Tagów, rs-rules-security Admin-Login-Security, joomla Licencja-Drupal, Licencja-ZenCart, Licencja-GPL2, Licencja-GPL3 Creative-Commons-License, joomla-2.5.x Kalendarz-Celtycki data-zodiak-data-majowie, moduł-GA-Gadu-gg, Moduł-Lotto-joomla K2-joomla Moduł-Kodownik-joomla kontakt-admin-3-pl Moduł-miłość-joomla Moduł-minutnik-joomla Google-Gadżet-strona-www Moduł-Multi-AnalogClock-joomla Grafika-Wektorowa-joomla Pascal-podstawy Pascal-instrukcja-if Pascal-pętla-for Pascal-Pętla-white-Repet Pascal-Instrukcja-Case Pascal Pascal-record Pascal-Tablice-(Macierze) Kolory-w-Pascalu Systemy-Liczbowe-10-16-8 Pak-top10-głosowanych-jQuery Waga-Bmi BF-Bear-Form Joomla+2.5+captcha+google BSD joomla, MP3 Creating, SEO, Admin tg RS BF The Celtic Forever Création Erstellen Toujours Immer Multi Contact-Admin-3-EN Contact-Admin-3-fr Contact-Admin-3-DE Open-Software-License-v.3.0-(OSL-3.0) System Interfejsy Mozilla joomla-metadane, seo-katalogi, wymiana Slider aukcjoner, Informator Osiemnaście CiastkoPl sem, Class Class-PDO-session login, registerUserClass, index PHP PDO, Class-ResponsiveCss zarabiarka-allegro Pogodynka Pogodynka Praca-Programisty Praca Funkcja-if Special+Arguments Simple-Captchta Jquery, Od 2 Konfiguracja 4.Instalacja 5.Konfiguracja 6.Instalacja 7.Konfiguracja 8.Metadane 9.Optymalizacja 10.Ciasteczka 11.System 12.Diagnostyka 13.Sesja Klasa Książka responsive Uniwersal Dodatek GoogAd.v1.4-polish-utf-8 Error Cooki Funkcje Linki Google Kompresja pdf, Dynamiczne template wycena Twoja Separation reklama ssd, bezpieczeństwo wzorce rekrutacja Zastosowanie Urządzenia Portale chat, dyski Platformy QUIZ 

Używamy cookies i podobnych technologii m.in. w celach: świadczenia usług, reklamy, statystyk. Korzystanie z witryny bez zmiany ustawień Twojej przeglądarki oznacza, że będą one umieszczane w Twoim urządzeniu końcowym. Pamiętaj, że zawsze możesz zmienić te ustawienia. To find out more about the cookies we use and how to delete them, see our privacy policy.

I accept cookies from this site.

EU Cookie Directive Module Information