2005年06月06日 星期一 15:39
to see if the list works now.
2005年06月06日 星期一 15:57
上次面试的时候一个老外问的,我说在getStaffList()中对于staffList做个 protected-copy,他没反应。 大家帮着想一想!谢谢啊! pilbic class Company { private List staffList; public List void getStaffList() { return staffList; } ..... } public class EvilAgency() { public void buildContact() { List stafflist = myCompany.getStaffList(); ..... stafflist.clear(); //how to prevent this occuring? ..... } ...... }
2005年06月06日 星期一 16:07
""" Not Found The requested URL /pipermail/python-chinese/ was not found on this server. """ 呜乎哀哉!还有首页的快速退订入口怎么也没有了?? 2005/6/6, Jacob Fan <jacob at exoweb.net>: > to see if the list works now. > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > -- [Time is unimportant, only life important!]
2005年06月06日 星期一 16:54
List stafflist = myCompany.getStaffList(); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 应该是下面这样吧??? List stafflist = Company.getStaffList(); -----Original Message----- From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of CaiJianFeng Sent: Monday, June 06, 2005 3:57 PM To: python-chinese at lists.python.cn Subject: [python-chinese] How to prevent calling the clear method of thelist? 上次面试的时候一个老外问的,我说在getStaffList()中对于staffList做个 protected-copy,他没反应。 大家帮着想一想!谢谢啊! pilbic class Company { private List staffList; public List void getStaffList() { return staffList; } ..... } public class EvilAgency() { public void buildContact() { List stafflist = myCompany.getStaffList(); ..... stafflist.clear(); //how to prevent this occuring? ..... } ...... } _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese
2005年06月06日 星期一 17:04
不好意思,说的不够清楚,myCompany是Company的一个实例,就代表某个公司吧。 EvilAgency在这里就是个保险机构,比如某个公司要为所有的员工上意外保险,就要和该公司每 个员工签署一份合同。 ----- Original Message ----- From: "Neo Chan (netkiller)" <neo.chen at achievo.com> To: <python-chinese at lists.python.cn> Sent: Monday, June 06, 2005 4:54 PM Subject: RE: [python-chinese] How to prevent calling the clear method ofthelist? > List stafflist = myCompany.getStaffList(); > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 应该是下面这样吧??? > List stafflist = Company.getStaffList(); > > -----Original Message----- > From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of CaiJianFeng > Sent: Monday, June 06, 2005 3:57 PM > To: python-chinese at lists.python.cn > Subject: [python-chinese] How to prevent calling the clear method of thelist? > > 上次面试的时候一个老外问的,我说在getStaffList()中对于staffList做个 > protected-copy,他没反应。 > 大家帮着想一想!谢谢啊! > > pilbic class Company { > private List staffList; > > public List void getStaffList() { > return staffList; > } > > ..... > } > > public class EvilAgency() { > > public void buildContact() { > > List stafflist = myCompany.getStaffList(); > ..... > stafflist.clear(); //how to prevent this occuring? > ..... > } > ...... > } > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese
2005年06月06日 星期一 23:48
CaiJianFeng wrote: > 上次面试的时候一个老外问的,我说在getStaffList()中对于staffList做个 > protected-copy,他没反应。 > 大家帮着想一想!谢谢啊! > > pilbic class Company { > private List staffList; > > public List void getStaffList() { > return staffList; > } > > ..... > } > > public class EvilAgency() { > > public void buildContact() { > > List stafflist = myCompany.getStaffList(); > ..... > stafflist.clear(); //how to prevent this occuring? > ..... > } > ...... > } > 做copy系统开销太大了,可以让getStaffList不直接返回staffList,而是返回一 个不具有clear方法的代理对象,可以考虑使用delegate pattern。 用python描述如下: class ImmutableList(object): def __init__(self, obj): self.__obj = obj def __getattr__(self, attr): return getattr(self.__obj, attr) def clear(self): raise AttributeError class Company(object): def getStaffList(self): return ImmutableList(self.__staffList) -- Qiangning Hong ___________________________________________________________ / No, I do not know what the Schadenfreude is. Please tell \ | me, because I'm dying to know. | | | | -- Homer Simpson | | | \ When Flanders Failed / ----------------------------------------------------------- \ \ \ ___ _____ ___ / \ / /| / \ | | / / | | | | | /____/ | | | | | | | | | | | | | {} | / | | | | |____|/ | | | | |==| | | | \___________/ | | | | |
Zeuux © 2025
京ICP备05028076号