keeB Posted August 23, 2007 Share Posted August 23, 2007 As a side note, can you call a function before you've defined it Huh Or does PHP put functions higher in processing precedence or something? <?php doSomething(); function doSomething() { print "hey mom, you suck!"; } ?> That works, if that's what you were asking Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-331510 Share on other sites More sharing options...
emehrkay Posted August 23, 2007 Share Posted August 23, 2007 http://www.php.net/~helly/php/ext/spl/ Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-331522 Share on other sites More sharing options...
matthewhaworth Posted August 23, 2007 Author Share Posted August 23, 2007 http://www.php.net/~helly/php/ext/spl/ Does PHP get more complex than what we've discussed in this thread? Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-331524 Share on other sites More sharing options...
matthewhaworth Posted August 23, 2007 Author Share Posted August 23, 2007 And if this is an abstract factory, then why is the class not abstract, because I mean, you can call the function "getShipping" from the class AND initiate the class, it's not abstract, to me the following example is just a regular factory pattern. And why's it called a 'factory' pattern? class shipping{ public static getShipping($company){ switch($company){ case 'fedex': return new fedex() break; case 'usps': return new usps(); break; } } abstract function calculateCost(); protected function ourMarkup(){ return 2;} } class fedex extends shipping{ public function calculateCost(){ return 4 + $this->ourMarkup(); } } class usps extends shipping{ public function calculateCost(){ return 3 + $this->ourMarkup(); } } I'm sorry, can someone answer this question? Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-331542 Share on other sites More sharing options...
keeB Posted August 23, 2007 Share Posted August 23, 2007 Factory means it's an object which creates and returns objects. Abstract factory means you have 3 things: 1. The Abstract Factory (in our case, an interface or abstract class) 2. ConcreteFactory (in the case above, Shipping) 3. ConcreteProducts (in the case above, USPS, FedEx, DHL, UPS..) Really, this page explains all of it: http://en.wikipedia.org/wiki/Abstract_factory_pattern Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-331597 Share on other sites More sharing options...
radalin Posted August 24, 2007 Share Posted August 24, 2007 Factory is something that creates generally same type of things but let's say different instances, right? A factory may create nike shoes but also adidas shoes. Every shoe implements the same interface. They wrap our feet and things like that. Let's sat you have a database object which connects to the database. You create it by: $db = new Datatabase(); Thing is when you pass from mysql to mssql, you should change all your syntax right? mysql_query must be replaced with mssql_query and it's a really annoying bussiness anyway. Let's say that you have used the factory method. When creating Database() you send it a database type to your Database object. It has a driver which executes your sql queries. So your database creates another object to execute your sql queries. This newly created drivers are specified to the database type, mysql has different syntax mssql has different types but they have the same method names as they implement the same interface. So whatever be your database driver you can call query() function. So you factory creates another object that object may create another objects and this goes like that. That's why it's called 'factory', it creates instances of different object with nearly the same functionality. I hope I was able to explain that clearly and without mistakes. Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-332953 Share on other sites More sharing options...
keeB Posted August 24, 2007 Share Posted August 24, 2007 I think what you just described is an Abstract Factory (a factory which returns a set of objects which implement the same interface) Quote Link to comment https://forums.phpfreaks.com/topic/66087-solved-encapsulation-polymorphism-interfaces-wtf/page/2/#findComment-333051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.