0
Nathim's Avatar, Join Date: Dec 2010
Newbie Member
Really very good job Mr. shabbi
thank U
0
nsures's Avatar, Join Date: Feb 2011
Newbie Member
Hello Shabbir,
Excellent article, however i have trouble getting the attachment project (97 KB when i DLed) , could you please look into this

Suresh
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by nsures View Post
Hello Shabbir,
Excellent article, however i have trouble getting the attachment project (97 KB when i DLed) , could you please look into this

Suresh
Hi suresh, I re-downloaded it and don't see any issues. If you still have issues getting the file email me and I will send you the file as an attachment.
xpertprogrammer like this
0
ashwinparmar's Avatar, Join Date: May 2011
Newbie Member
I have solved your problem.
-- Ashwin Parmar


Code:
<?php
  abstract class Control {
      abstract function Show();
   }

   class WinButton extends Control {
      function Show() {
         echo "I'm a WinButton: ";
      }
   }

   class MacButton extends Control {
      function MacButton() {
        echo "MacButton";
      }
      function Show() {
         echo "I'm an MacButton: ";
      }
   }

   class WinLabel extends Control {
      function Show() {
         echo "I'm a WinLabel: ";
      }
   }

   class MacLabel extends Control {
      function Show() {
         echo "I'm an MacLabel: ";
      }
   }

    abstract class GUIFactory {
      static function GetFactory() {
            if (TRUE) return new MacFactory();
            else return new WinFactory(); 
      }
      abstract function CreateButton();
      abstract function CreateLabel();
   }   
    
   class WinFactory extends GUIFactory{
        
        public function WinFactory() {
            $btn = new WinButton();
            $lbl = new WinLabel();
        }
   
        function CreateButton() {
            print_r($btn);
            return $btn;
        }
        function CreateLabel() {
            return $lbl;
        }
   }

   class MacFactory extends GUIFactory {
      // Its there just to have the Classdiagram going
        
      function CreateButton() {
         return new MacButton();
      }

      function CreateLabel() {
         return new MacLabel();
      }
   }

 
    $factory = GUIFactory::GetFactory(); // Return MacFactory
    $button = $factory->CreateButton();  // Return MacButton
    echo $button->Show();
    
    $label = $factory->CreateLabel();
    echo $label->Show();
    
?>
================================================== =======
Quote:
Originally Posted by ngungo View Post
This is my first post. I try to convert the Abstract Factory class in c# to php. Of course, it does not work. Can you correct it for me, or give me a hint. Thanks.
--ngungo

Code:
<?php
   class GUIFactory {
      function GetFactory() {
            if (TRUE) return new MacFactory();
            else return new WinFactory(); 
      }
      public function CreateButton() {};
      public function CreateLabel() {};
   }

   class WinFactory extends GUIFactory {
      // Its there just to have the Classdiagram going
      $btn = new WinButton();
      $lbl = new WinLabel();
      public override function CreateButton() {
         return $btn;
      }

      public override function CreateLabel() {
         return $lbl;
      }
   }

   class MacFactory function GUIFactory {
      // Its there just to have the Classdiagram going
      $btn = new MacButton();
      $lbl = new MacLabel();
      public override function CreateButton() {
         return $btn;
      }

      public override function CreateLabel() {
         return $lbl;
      }
   }

   abstract class Control {
      public abstract function Show();
   }

   class WinButton extends Control {
      public override function Show() {
         echo "I'm a WinButton: ";
      }
   }

   class MacButton extends Control {
      public override function Show() {
         echo "I'm an MacButton: ";
      }
   }

   class WinLabel extends Control {
      public override function Show() {
         echo "I'm a WinLabel: ";
      }
   }

   class MacLabel extends Control {
      public override function Show() {
         echo "I'm an MacLabel: ";
      }
   }
   
    $factory = GUIFactory.GetFactory();
    $button = factory.CreateButton();
    echo $button->Show();
    
    $label = factory.CreateLabel();
    echo $label->Show();
?>

Last edited by shabbir; 16May2011 at 19:11.. Reason: Code blocks
0
ashwinparmar's Avatar, Join Date: May 2011
Newbie Member
PHP Code:
<?php
  
abstract class Control {
      abstract function 
Show();
   }

   class 
WinButton extends Control {
      function 
Show() {
         echo 
"I'm a WinButton: ";
      }
   }

   class 
MacButton extends Control {
      function 
MacButton() {
        echo 
"MacButton";
      }
      function 
Show() {
         echo 
"I'm an MacButton: ";
      }
   }

   class 
WinLabel extends Control {
      function 
Show() {
         echo 
"I'm a WinLabel: ";
      }
   }

   class 
MacLabel extends Control {
      function 
Show() {
         echo 
"I'm an MacLabel: ";
      }
   }

    abstract class 
GUIFactory {
      static function 
GetFactory() {
            if (
TRUE) return new MacFactory();
            else return new 
WinFactory(); 
      }
      abstract function 
CreateButton();
      abstract function 
CreateLabel();
   }   
    
   class 
WinFactory extends GUIFactory{
        
        public function 
WinFactory() {
            
$btn = new WinButton();
            
$lbl = new WinLabel();
        }
   
        function 
CreateButton() {
            
print_r($btn);
            return 
$btn;
        }
        function 
CreateLabel() {
            return 
$lbl;
        }
   }

   class 
MacFactory extends GUIFactory {
      
// Its there just to have the Classdiagram going
        
      
function CreateButton() {
         return new 
MacButton();
      }

      function 
CreateLabel() {
         return new 
MacLabel();
      }
   }

 
    
$factory GUIFactory::GetFactory(); // Return MacFactory
    
$button $factory->CreateButton();  // Return MacButton
    
echo $button->Show();
    
    
$label $factory->CreateLabel();
    echo 
$label->Show();
    
?>
0
Lulugreen's Avatar, Join Date: May 2011
Go4Expert Member
Nice article! It is very helpful for me! Thanks!
0
r0o0cky's Avatar, Join Date: Jul 2011
Newbie Member
Which pattern is best for an ASP.NET website with SQL server database and .NET framework 2.0, Thanks.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by r0o0cky View Post
Which pattern is best for an ASP.NET website with SQL server database and .NET framework 2.0, Thanks.
The application of pattern depends on lot of factors and in your case the type of website you are creating. An ecommerce site in ASP and a CMS site in ASP may not have the same pattern applied.
xpertprogrammer like this
0
r0o0cky's Avatar, Join Date: Jul 2011
Newbie Member
Quote:
Originally Posted by shabbir View Post
The application of pattern depends on lot of factors and in your case the type of website you are creating. An ecommerce site in ASP and a CMS site in ASP may not have the same pattern applied.
Thanks, Shabbir. I know that we have to take in account the type of application we are developing. We often hear of MVC or MVP, are these design patterns or something else.

I wanted to know what basic pattern a new bie should follow, which is easy to maintain and work on. Or Are there some frameworks we should use.

Mostly ASP.NET websites are developed using the code-behind page logic, or some develop interfaces implemented by the code-behind page and than pass the page instance to a controller or presenter.

Any help from Shabir or other members, Thanks.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by r0o0cky View Post
Thanks, Shabbir. I know that we have to take in account the type of application we are developing. We often hear of MVC or MVP, are these design patterns or something else.

I wanted to know what basic pattern a new bie should follow, which is easy to maintain and work on. Or Are there some frameworks we should use.

Mostly ASP.NET websites are developed using the code-behind page logic, or some develop interfaces implemented by the code-behind page and than pass the page instance to a controller or presenter.

Any help from Shabir or other members, Thanks.
To be honest I cannot name one pattern that every newbie should start with.