正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology modularization of the system, by isolating the common methods in a single place, for easy maintenance and change 6.001 Notes: Section 14.2 Slide 14.2.1 How to design interactions between objects o our first goal is to examine the paradigm of constructing Focus on classes objects ystems around objects, and for now we are going to ignore the Relationships between classe issue of how to describe these object systems in Scheme, we will f interactions tha instead initially focus on the abstract use of object-based instances of classes systems. Thus, we will primarily consider the classes of objects For now, assume the following interface to an object we might want in a system, and the range of interactions that we lask <object> <method> <arguments>) will need to support between objects. For now, we will simply assume that given an instance of a class, that is an object, we can send that object a message using the form (ask <object> <method> <arguments In other words we can use some Scheme interface(which we will define later)based on the ask procedure, which takes as arguments an object, a name of a method (something we want the object to do), and some set of arguments that specify details of the method, and ask will cause the object to execute the specified method. We will return to details of this shortly An initial class hierarchy lide14.2.2 We start with a class for people, which we call the person class Each instance of a person has two class variables, holding the persons first and last name. Each instance also has two methods. The say method causes the person to say something WHOAREYOU? (ask persom-1 HOAREYoUP) The whoareyou? method causes the person to indicate their first The class diagram for this class is shown in the slide. As well we will assume some constructor for making instances of the class(we will get to details of this shortly), and we can see how asking an instance of this class to say something or to identify au themselves causes actions in the system6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. modularization of the system, by isolating the common methods in a single place, for easy maintenance and change. 6.001 Notes: Section 14.2 Slide 14.2.1 So our first goal is to examine the paradigm of constructing systems around objects, and for now we are going to ignore the issue of how to describe these object systems in Scheme; we will instead initially focus on the abstract use of object-based systems. Thus, we will primarily consider the classes of objects we might want in a system, and the range of interactions that we will need to support between objects. For now, we will simply assume that given an instance of a class, that is an object, we can send that object a message using the form (ask <object> <method> <arguments>). In other words, we can use some Scheme interface (which we will define later) based on the ask procedure, which takes as arguments an object, a name of a method (something we want the object to do), and some set of arguments that specify details of the method, and ask will cause the object to execute the specified method. We will return to details of this shortly. Slide 14.2.2 We start with a class for people, which we call the person class. Each instance of a person has two class variables, holding the person’s first and last name. Each instance also has two methods. The say method causes the person to say something. The whoareyou? method causes the person to indicate their first name. The class diagram for this class is shown in the slide. As well, we will assume some constructor for making instances of the class (we will get to details of this shortly), and we can see how asking an instance of this class to say something or to identify themselves causes actions in the system
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有