关于 Coldfusion 8 中的 getter、setter 和组件的问题
因此,我正在尝试学习和利用组件来使我的代码变得更好...
我了解 getter 和 setter 是什么...但是,我不确定将它们放在哪里以适应我的组件的工作方式。我的组成部分是一个具有唯一 ID 和部门的教师。我希望所有信息都采用结构形式,因为每个教师都有很多信息。我的 init 方法将初始化特定实例的 id 和部门,然后继续调用一个查询,将其余信息填充到一个结构中。我只是不确定如何为 id 和部门执行 getter 和 setter...我是否只是初始化一个“空白”实例,然后使用 getter/setter 来实际执行输入?
还有关于组件的另一个想法/问题: 我的组件是否应该仅具有处理单个实体(个人)的方法,或者我的组件中是否也可以具有处理整体的方法(例如针对所有个体的搜索功能)。 ...或者我应该将两者分开吗?
谢谢!
So, I'm trying to learn and utilize components to make my code better...
I understand what getters and setters are...however, I'm not sure where to put them in respect to how my component works. My component is a faculty which has a unique id and department. I want all my information in a struct form because each faculty has a lot of information. My init method would initialize the id and the department of the specific instance and then proceed to call a query that will populate the rest of the information into a struct. I'm just not sure how to do the getters and setters for the id and department...do I just init a "blank" instance and then use a getter/ setter to actually do the input?
Also another thought/ question regarding components:
Should my component only have methods that deal with single entities (individuals) or can I also have methods in my component that deals with the whole (like a search function for all individuals).
...or should I separate the two?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设置教员 CFC 的 CF8 方法。请注意,我没有使用“实例”范围,因为当升级到 CF9 时,您可以删除 getter/setter 并将
accessor=true
添加到cfcomponent
你就完成了。但是,当您需要从 CFC 中获取数据作为 DAO 的结构来持久保存对象时,您可能会发现添加人工“实例”范围很有用。通常在 CF 世界中(受到 Java 世界的启发),我们会将它们分离到没有状态的
FooService
中,并将您的FooService
缓存为Application< 中的单例。 /代码>范围。然后实现与 FooDAO(数据访问对象)层中的数据库对话的创建读取更新删除(CRUD)方法。然后,您的
FooService
将调用FooDAO
中的 CRUD 方法来为您读取(并填充)Foo
对象。Here's a CF8 way of setting up the faculty CFC. Notice that I didn't use the 'instance' scope 'cause when it's time to upgrade to CF9, u can remove the getters/setters and add
accessor=true
to thecfcomponent
and you're done. However, you may find adding an artificial 'instance' scope useful when you need to get the data out of the CFC as a struct for DAO to persist your object.Usually in the CF world (inspired by the Java world), we'd separate them into
FooService
with no state, and cache yourFooService
as singleton inApplication
scope. Then implement the Create Read Update Delete (CRUD) methods that talk to the DB inFooDAO
(data access object) layer. YourFooService
would then call the CRUD methods inFooDAO
to read (and populate) aFoo
object for you.