Interaction between objects

http://stackoverflow.com/questions/3744345/object-oriented-style-programming-for-interaction-between-objects?rq=1

One thing I‘ve noticed is that people that are new to OOP get caught up in trying to map the physical world into the code they are writing. Do you really care that John and Betty are people or are you actually wanting to depict a bank account? I think your choice of objects in the example actually make it harder to figure out the solution to the problem.

The important parts of this are 1) Where to put the logic of how to move the money. 2) Where to store the data of how much money each person has.

You need to decide if you want to talk about the problem in the context of a person or a customer of a bank (may be a person, company, or something else). I‘m guessing you are talking about a customer because assuming it is a person would be limiting and misleading. Also, a Bank is a pretty generic term, is it the big brick building with people inside of it or is it the online website with several different pages that do different things. A bank account object can have a method (possibly static depending on how you decide to store your data and what all you are going to use your object for) that knows how to transfer from one account to another. The logic of how to transfer does not belong to Betty or John or a bank, it belongs to a bankAccount which can have special logic based on the type of account if there are fee‘s involved or the like. If you gave that logic to the bank you would end up with a giant bank class with methods for everything from greating a customer to dealing with money in very specific account types. Each account type my have different rules for how it handles transfers. Think of times where you may want to show a transfer or deposit as pending.

If you are just solving the problem of transfering money, there is no need to create a bunch of objects. Based on the known requirements and presumed future requirements the below would be a good choice. CheckingAccount.Transfer(johnsAccountNo, bettysAccountNo, amount)

http://codereview.stackexchange.com/questions/63441/object-interaction-in-oop-especially-python

You should try to find a better way to decouple them. An idea cold be removing the need of keeping a list of groups in Person and a list of people in Group. You could do it by introducing a third class, let‘s call it Subscriptions, that will contain a list of subscriptions. An easy way to do that could be a (person, group) pair. That class will then offer all the methods to edit subscriptions (with a subscribe(person, group) and an unsubscribe(person, group) as well as methods to query them, like get_groups(person) or get_members(group).

时间: 2024-10-24 14:01:32

Interaction between objects的相关文章

Propagation of Visual Entity Properties Under Bandwidth Constraints

1. Introduction The Saga of Ryzom is a persistent massively-multiplayer online game (MMORPG) released in September 2004 throughout Europe and North America, localised in 3 languages so far. It has been developed by Nevrax since 2000, and was taken ov

Prism 4 文档 ---第8章 导航

作为同用户具有丰富的交互的客户端应用程序,它的用户界面(UI)将会持续不断的更新来反映用户工作的当前的任务和数据.用户界面可以进行一段时间相当大的变化作为用户交互的应用程序中完成各种任务.通过该应用程序协调这些用户界面的变化的过程通常被称为导航. 经常,导航意味着某些控件将会从UI中移除,其他的控件将会被添加到UI中.在另外的情况下,导航也意味着一个或多个存在的控件的可视化状态被更新.---例如,一些控件可能被简单的隐藏或收缩而另外的一些控件被显示后展开.类似的,导航可能意味着一个控件展示的绑定

uml精粹——1.介绍 & 2.开发过程

1.介绍 [使用uml的方式] 把uml当做草图sketch.顺向工程forward engineering在写代码前会绘制uml.而逆向工程reverse engineering根据已有的代码绘制uml来帮助理解. 把uml当做设计图blueprint是为了完整性completeness.在顺向工程中工作是构建详细设计的设计师会绘制设计图来让程序员更好的写代码实现.这个设计需要足够完整,里面所有的设计决策design decisions都被列出laid out,让程序员能够轻松的照着做而只需要

Interaction Between Threads and Securable Objects

When a thread attempts to use a securable object, the system performs an access check before allowing the thread to proceed. In an access check, the system compares the security information in the thread's access token against the security informatio

advanced dom scripting dynamic web design techniques Chapter 2 CREATING YOUR OWN REUSABLE OBJECTS

JavaScript is all about objects. Objects are the foundation of everything, so if you’re unfamiliar with objects, you’re going to learn quickly. The goal of this book is not to be a JavaScript or DOM code reference, but in order to make sure you under

The Runtime Interaction Model for Views-UI布局事件处理流程

The Runtime Interaction Model for Views Any time a user interacts with your user interface, or any time your own code programmatically changes something, a complex sequence of events takes place inside of UIKit to handle that interaction. At specific

represent states with objects

1. The behavior of objects in the real world is more complex than simply being in one state at a time. the conditions of an Object being in more than one state at a  time is called "concurrency" or concurrent states. CSE-307-Software-Engineering

Python integer objects implementation

http://www.laurentluce.com/posts/python-integer-objects-implementation/ Python integer objects implementation May 15, 2011 This article describes how integer objects are managed by Python internally. An integer object in Python is represented interna

The science of interaction交互元素与知识构建过程的查询方式

The science of interaction 摘要 可视分析中增长的感知交互和查询无法摆脱.通过交互操作可视界面---分析的论述----构建.测试.精炼,及共享知识.本文反映可视化研究与开发会议中的交互挑战.识别最近可视分析研究典范,在真实的交互科学目标具有真实的进步,必须包括理论和可测试关于人与信息交互最合适机制.七个领域未来5年可视分析研究:普适,表征交互:获取用户意向性:基于知识的界面:交互评估.最终,科学交互目标是支持可视分析,人.机交互群体通过感知和实现最好的实践,在可视显示的