哪个是更好的OOP,为什么? [英] Which is better OOP, and why?
问题描述
我已经看到了将值传递给类的不同方法:
$ db = new mysqlclass(''localhost'',''user'',''passwd'' ,''数据库'');
.....
或
$ db = new mysqlclass()
$ db-> host =''localhost'';
$ db-> user =''user'';
$ db-> passwd =''passwd'';
$ db-> database =''database'';
.....
对我来说,第二个看起来更像打字。但是如果
类的参数列表发生变化,后者就不会受到影响。我试图将我的
大脑(踢和抓)拖入OOP。对此有任何想法将是
赞赏。
谢谢
Dan
I have seen differing ways to pass values to a class:
$db=new mysqlclass(''localhost'',''user'',''passwd'',''database'') ;
.....
OR
$db=new mysqlclass()
$db->host=''localhost'';
$db->user=''user'';
$db->passwd=''passwd'';
$db->database=''database'';
.....
To me, the second looks like more typing. But if the argument list to the
class changes, the latter would not be effected. I am trying to drag my
brain (kicking and scratching) into OOP. Any thoughts on this would be
appreciated.
Thanks
Dan
推荐答案
db = new mysqlclass(''localhost'',''user'',''passwd'',''database'');
.....
或
db=new mysqlclass(''localhost'',''user'',''passwd'',''database'') ;
.....
OR
db = new mysqlclass()
db=new mysqlclass()
db-> host =''localhost'';
db->host=''localhost'';
这篇关于哪个是更好的OOP,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!