OBJECT-ORIENTED ANALYSIS AND DESIGNWith application 2nd phần 10 pdf

54 318 0
OBJECT-ORIENTED ANALYSIS AND DESIGNWith application 2nd phần 10 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Object-Oriented Programming Languajes 479 Flegal, Ted Kaehler, Diana Merry, and Steve Putz. Among other important roles that they played, Adele Goldberg and David Robson served as chroniclers of the Smalltalk project. Table A-1 Smalltalk There are five identifiable releases of Smalltalk, indicated by their year of release: Smalltalk- 72, -74, -76, -78, and the most current incarnation, SmalItalk80. SmalItalk-72 and -74 did not provide support for inheritance, but they did lay much of the conceptual foundation of the language, including the ideas of message passing and polymorphism. Later releases of the language turned classes into first-class citizens, thus completing the view that everything in the environment could be treated as an object. Smalltalk-80 has been ported to a variety of machine architectures. There is also an important dialect of SmalItalk provided by Digitalk, Smalltalk/V, that is very similar to SmalItalk-80 and is available on the IBM PC (Windows and OS/2) and Macintosh. Except for the user interface classes, the class libraries are quite similar to each other. Also like SmalItalk-80, there is a development environment and development tools that are similar in capability, but different in structure and function [4]. Overview Ingalls states that "the purpose of the Smalltalk project is to support children of all ages in the world of information. The challenge is to identify and harness metaphors of sufficient simplicity and power to allow a single person to, have access to, and creative control over, information which ranges from number and text through sounds and images" [5]. To this end, Object-Oriented Programming Languajes 480 SmalItalk is built around two simple concepts: everything is treated as an object, and objects communicate by passing messages. Table A-1 summarizes Smalltalk's features, relative to, the seven elements of the object model. Although the table does not indicate it, multiple inheritance is possible by the redefinition of certain primitive methods [6]. Example Consider the problem in which we have a heterogeneous list of shapes, in which each particular shape object might be a circle, a rectangle, or a solid rectangle (this is similar to the problem we introduced in Chapter 3). Smalltalk has an extensive class library that already contains classes for circles and rectangles, and so our solution in this language would be almost trivial; this demonstrates the importance of reuse. However, for the sake of comparison, lets assume that we only have primitive classes for drawing lines and arcs. Therefore, we might define the class AShape as follows: Object subclass: *AShape instanceVariableNames: 'theCenter' classVariableNames: ‘’ poolDictionaries: ‘’ category: 'Appendix' Initialize "Initialize the shape" theCenter := Point new setCenter: aPoint "Set the center of the shape" theCenter := aPoint center “Retun the center of the shape" ^theCenter draw «Draw the shape" self subclassResponsibility We may next define the subclass ACircle as follows: AShape subclass: #ACircle instanceVariableNames: 'theRadius' classVariableNames: ‘’ poolDictionaries: ‘’ category: 'Appendix' Object-Oriented Programming Languajes 481 setRadius: anInteger "Set the radius of the circle" theRadius := anInteger radius “Return the radius of the circle" ^theRadius draw “Draw the circle” |anArc index | anArc Arc new. index := 1. [index <= 41] whileTrue: [anArc center: theCenter radius: theRadius quadrant: index. anArc display. index := index+ 1] Continuing, the subclass ARectangle may be defined as follows: AShape subclass: #ARectangle instanceVariableNames: 'theNeight theWidth' classVariableNames: ‘’ poolDictionaries: ‘’ category: 'Appendix draw “Draw the rectangle" |aLine upperLeftCorner | aLine := Line new. upperLeftComer := theCenter x - (theWidth / 2) 0 (theCenter y - (theHeight 12). aLine beginPoint: upperLeftCorner. aLine endPoint: upperLeftCorner x + theWidth 0 upperLeftComer y. aLine display. aLine beginPoint: aLine endPoint. aLine endPoint: upperLeftCorner x + theWidth 0 (upperLeftCorner y + theHeight). aLine display. aLine beginPoint: aLine endPoint. aLine endPoint: upperLeftCorner x 0 (upperLeftCorner y + theHeight). aLine display. aLine beginPoint: aLine endPoint. aLine endPoint: upperLeftCorner. Object-Oriented Programming Languajes 482 aLine display setHeight: anInteger "Set the height of the rectangle” theHeight := anInteger setWidth: anInteger "Set the width of the rectangle" theWidth := anInteger height "Return the height of the rectanglel" ^theHeight width "Return the width of the rectangle" ^theWidth Lastly, the subclass ASolidRectangle may be defined as: ARectangle subclass: #ASolidRectangle instanceVariableNames: ‘’ classVariableNames: ‘’ poolDictionaries: ‘’ category: 'Appendix' draw “Draw the solid rectangle” | upperLeftCorner lowerRightCorner | super draw. upperLeftCorner := theCenter x - (theWidth quo: 2) + 1 @ (theCenter y - (theHeight quo: 2) + l). lowerRightCorner :=(:pperLeftCorner x + theWidth - 1 @ (upperLeftCorner y + theHeight - l). Display fill: (upperLeftCorner corner: lowerRightCorner) mask: Form gray References The primary references for Smalltalk are Smalltalk-80. The Language, by Goldberg and Robson [7]; Smalltalk-80. The Interactive Programming Environment, by Goldberg [8]; and Smalltalk-80. Bits of History, Words of Advice, by Krasner [9]. LaLonde and Pugh [10] explore Smalltalk-80 in great depth, including both the class libraries and application development. Object-Oriented Programming Languajes 483 A.3 Object Pascal Background Object Pascal was created by developers from Apple Computer (some of whom were involved in the development of Smalltalk), in conjunction with Nalaus Wirth, the designer of Pascal. Object PascaPs immediate ancestor is Clascal, an object-oriented version of Pascal for the Lisa. Object Pascal was made publicly available in 1986 and is the first object-oriented programming language supported by the Macintosh Programmer's Workshop (MPW), the development environment for Apple's family of Macintosh computers. The class library for MPW, called MacApp, provides the frameworks for constructing applications that conform to the Macintosh user interface guidelines. Table A-2 Object Pascal Overview As Schmucker states, "Object Pascal is a 'bare bones' object-oriented language. It makes no provision for class methods, class variables, multiple inheritance, or metaclasses. These concepts were specifically excluded in an attempt to streamline the learning curve encountered by most novice object-oriented programmers" [11]. Object-Oriented Programming Languajes 484 We summarize the features of Object Pascal in Table A-2, relative to the seven elements of the object model. References The primary reference for Object Pascal is the MPW Object Pascal Reference from Apple [12] A.4 C++ Background C++ was designed by Bjarne Stroustrup of AT&T Bell Laboratories. The immediate ancestor of C++ is a language called C with Classes, also developed by Stroustrup in 1980. In turn, C with Classes was heavily influenced by the languages C and Simula. C++ is largely a superset of C. However, in one sense, C++ is simply a better C, in that it provides type checking, overloaded functions, and many other improvements. Most importantly, however, C++ adds object-oriented programming features to C. Table A-3 C++ There have been several major releases of the C++ language. Version 1.0 and its minor releases added basic object-oriented programming features to C, such as single inheritance Object-Oriented Programming Languajes 485 and polymorphism, plus type checking and overloading. Version 2.0, released in 1989, improved upon the previous versions in a variety of ways (such as the introduction of multiple inheritance), based upon extensive experience with the language by a relatively large user community. Version 3.0, released in 1990, introduced templates (parameterized classes) and exception handling. The ANSI X3jl6 C++ committee has recently adopted proposals for namespace control (consistent with our notion of class categories) and run-time type identification. Early translator technology for C++ involved the use of a preprocessor for C, called cfront. Because this translator emitted C code as an intermediate representation, it was possible to port C++ to virtually every UNIX architecture quite quickly. Now, C++ translators and native compilers are available commercially for almost every kind of instruction-set architecture. Overview Stroustrup states that "C++ was primarily designed so that the author and his friends would not have to program in assembler, C, or various modern high-order languages. Its main purpose is to make writing good programs easier and more pleasant for the individual programmer. There never was a C++ paper design; design, documentation, and implementation went on simultaneously" [13]. C++ corrects many of the deficiencies of C, and adds to the language support for classes, type checking, overloading, free store management, constant types, references, inline functions, derived classes, and virtual functions [14]. We summarize the features of C++ in Table A-3 on page 481, relative to the seven elements of the object model. Example Again we reimplement the shape problem. The common style in C++ is to place the outside view of each class in header files. Thus, we may write: struct Point { int x; int y; }; class Shape { public: Shape(); void setCenter(Point p); virtual void draw() = 0; Point center() const; private: Point theCenter; Object-Oriented Programming Languajes 486 }; class Circle : public Shape { public: Circle(); void setRadius(int r); virtual void draw(); int radius() const; private: int theRadius; }; class Rectangle : public Shape { public: Rectangle(); void setHeight(int h); void setWidth(int w); virtual void Draw(); int height() const; int width() const; private: int theHeight; int theWidth; }; class SolidRectangle : public Rectangle { public: virtual void draw(); }; The definition of C++ does not include a class library. For our purposes, we assume the existence of a programmatic interface to X Windows, and the global objects Display, Window, and GraphicsContext (which are needed by Xlib). Thus, we may complete the methods above in a separate file, as follows: Shape::Shape() { theCenter.x = 0; theCenter.y = 0; }; void Shape::setCenter(Point p) { theCenter = p; }; Point Shape::centero const { return theCenter; }; Circle::Circleo : theRadius(0) {} Object-Oriented Programming Languajes 487 void Circle::setRadius(int r) { theRadius = r; }; void Circle::draw() { int X = (centero.x - theRadius); int Y = (centero.y - theRadius); XDrawArc(Display, Window, GraphicsContext, X, Y, (theRadius * 2), (theRadius * 2), 0, (360 * 64)); }; int Circle::radius () const { return theRadius; }; Rectangle::Rectangle() : theMeight(0), theWidth(0) {} void Rectangle::setHeight (int h) { theHeight = h; }; void Rectangle::setWidth (int w) { theWidth = w; }; void Rectangle::draw() { int X = (center().x - (theWidth 2)); int Y = (center().y - (theHeight 2)); XDrawRectangle(Display, Window, GraphicsContext, X, Y, theWidth, theHeight); }; int Rectangle::height() const { return theHeight; }; int Rectangle::width() const { return theWidth; }; void SolidRectangle::draw() { Rectangle::draw(); int X = (center().x - (width() / 2)); int Y = (center() y - (height() / 2)); gc oldGraphicsContext = GraphicsContext; Object-Oriented Programming Languajes 488 XSetForeground(Display, GraphicsContext, Gray); XDrawFilled(Display, Window, GraphicsContext, X, Y, width(), height()); GraphicsContext = oldGraphicsContext; }; References The primary reference for C++ is the Annotated C++ Reference Manual by Ellis and, Stroustrup [15]. Stroustrup [16] provides in-depth coverage of the language and its use in the context of object-oriented design. A.5 Commn Lisp Object System Background There are literally dozens of dialects of Lisp, including MacLisp, Standard Lisp, SpiceLisp, S-1 Lisp, Nil, ZetaLisp, InterLisp, and Scheme. Starting in the early 1980's, a plethora of new dialects of Lisp emerged that supported object-oriented programming, many of which were invented to support ongoing research in knowledge representation. Spurred by the success in standardizing Common Lisp, a similar effort was undertaken in 1986 to standardize these object-oriented dialects. The idea of standardization was put forth at the summer 1986 ACM Lisp and Functional Programming Conference, resulting in the formation of a special, subcommittee as part of the X3jl3 ANSI committee (for the standardization of Common Lisp). Because this new dialect was conceived to be a proper superset of Common Lisp, it was called the Common Lisp Object System, or CLOS for short. Daniel Bobrow chaired the committee, whose members included Sonya Keene, Linda DeMichiel, Patrick Dussud, Richard Gabriel, james Kempf, Gregor Kicazles, and David Moon. The design of CLOS was heavily influenced by the languages New Flavors and CommonLoops. After about two years of work, the complete specification of CLOS was published in late 1988. [...]... S., Hecht, A., Tryon, D., and Hywari, W September 1988 Object-Oriented Analysis: Theory and Practice, Course Notes, in Object-Ollented Programming Systems, Languages, and Applications San Diego, CA: OOPSLA'88, p 1.3 [17] Symons, C 1988 Function Point Analysis: Difficulties and Improvements IEEE Transactions on Software Engineering vol.(14)1 [18] Dreger, B 1989 Function Point Analysis Englewood Cliffs,... Design: Types, Structures, and Abstractions Handbook of Software Engineering New York, NY: Van Nostrand Reinhold, p 253 [6] Macintosb MacApp 1 1 1 Programmers Reference 1986 Cupertino, CA: Apple Computer, p 2 [7] Bhaskar, K October 1983 How Object-Oriented Is Your System? SIGPLANNotices vol 18 (10) , p 8 [8] Stefik, M and Bobrow, D Winter 1986 Object-Oriented Programming: Themes and Variations, AIMagazine... Snyder Encapsulation, p 39 [28] Cardelii, L and Wegner, P On Understanding Types, Data Abstraction, and Polymorphism December 1985 ACM Computing Surveys vol 17(4), p 475[29] As quoted in Harland, D., SzypIewski, M., and Wainwright, J October 1985 An Altemative View of Polymorphism SIGPLANNotices vol 20 (10) [30] Kaplan, S and johnson, R july 21, 1986 Designing and Implementingfor Reuse Urbana, IL: University... [28] Wirth, N 1986 Algoriffina and Data Structures Englewood Cliffs, Nj: Prentice-Hall [29] Daffi, 0., Dijkstra, E., and Hoare, C A R 1972 Structured Programming London, England: Academic Press [30] Mills, H., Linger, R., and Hevner, A 1986 Principles ofInfonnation System Design andAnalysis Orlando, FL: Academic Press [31] Jackson, M 1975 Principles ofProgram Design Orlando, FL: Academic Press [32]... Search of an Object-Oriented Development Process Joumal of Object-Ofiented Programming vol 2(1), p 61 [53] Stroustrup, B 1986 7-be C++ Programming Language Reading, MA: Addison Wesley, p 7 [54] Halbert, D and O'Brien, P September 1988 Using Types and inheritance in Object-Oriented Programming IEEE Software vol 4(5), p 75 [55] Stefik, M and Bobrow, D Winter 1986 Object-Oriented Programming: Themes and Variations,... Everette, WA: Object-Oriented Programming for Smalltalk Applications Developers Association vol 1(4), p 6 [62] Russo, V., Johnston, G., and Campbell, R September 1988 Process Management and Exception Handling in Multiprocessor Operating Systems Using ObjectOriented Design Techniques SIGPLAN Notices vol 230 1), p 249 [63] Englemore, R and Morgan, T 1988 Blackboard Systems Wokingham, England: Addison-Wesley,... [13] Bear, S., Allen, P., Coleman, D., and Hayes, F Graphical Specification of ObjectOriented Systems Object-O?Iented Programming Systems, Languages, and Applications Ottawa, Canada: OOPSLA'90 [14] Rumbaugh, Object-O?Iented Modeling and Design [15] Jacobson, I., Christerson, M., Jonsson, P., and Overgaard, G 1992 Object-Oriented Software Engineering Workingham, England: Addison-Wesley Publishing Company... Structured Analysis and System Specification Englewood Cliffs, Nj: Prentice-Hall [36] Yourdon, E 1989 Moderri StructuredAnalysis Englewood Cliffs, Nj: Prentice-Hall [37] Gane, C and Sarson, T 1979 Structured Systems Analysis Englewood Cliffs, Nj: Prentice-Hall [38] Ward, P and Mellor, S 1985 Structured Developmentfor Real-Time Systems Engle-wood Cliffs, Nj: Yourdon Press [39] Hatley, D and Pirbhai,... Danforth, S and Tomlinson, C March 1988 Type Theories and Object-Oriented Programming ACH Computing Surveys vol 20(1), P 34 [66] Liskov 1988, p 23 [67] As quoted in Liskov 1980, p 67 [68] Zilles, S 1984 Types, Algebras, and Modeling, in On Conceptual Modeling Perspectivesfrom Artificial Intelligence, Databases, and Programming Languages New York, NY: Springer-Verlag, p 442 [69] Borning, A and Lngalls,... Implement Shared Behavior in Object-Oriented Systems SIGTEANNotices vol 21(11) [24] Rumbaugh, 1991 p 312 [25] Brachman, R October 1983 "at IS-A Is and Isn't: An Analysis of Taxonomic Links References 505 in Semantic Networks LEEE Computer vol 16 (10) , p 30[26] Micallef, J April/May 1988 Encapsulation, ReusabilitY, and Extensibility in ObjectOriented Programming Languages journal of Object-Oriented Programming . standardizing Common Lisp, a similar effort was undertaken in 1986 to standardize these object-oriented dialects. The idea of standardization was put forth at the summer 1986 ACM Lisp and. H., Linger, R., and Hevner, A. 1986. Principles ofInfonnation System Design andAnalysis. Orlando, FL: Academic Press. [31] Jackson, M. 1975. Principles ofProgram Design. Orlando, FL: Academic. K. October 1983. How Object-Oriented Is Your System? SIGPLANNotices vol. 18 (10) , p. 8. [8] Stefik, M. and Bobrow, D. Winter 1986. Object-Oriented Programming: Themes and Variations, AIMagazine

Ngày đăng: 12/08/2014, 21:21

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan