【正文】
tical characteristics (data elements) and behaviors (functionality), a class is really a data type because a floating point number, for example, also has a set of characteristics and behaviors. The difference is that a programmer defines a class to fit a problem rather than being forced to use an existing data type that was designed to represent a unit of storage 大連交通大學(xué) 2020 屆本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 4 in a machine. You extend the programming language by adding new data types specific to your needs. The programming system weles the new classes and gives them all the care and typechecking that it gives to builtin types. The objectoriented approach is not limited to building simulations. Whether or not you agree that any program is asimulation of the systemyou’re designing, the use of OOP techniques can easily reduce a large set of problems to a simple solution. Once a class is established, you can make as many objects of that class as you like, and then manipulate those objects as if they are the elements that exist in the problem you are trying to solve. Indeed, one of the challenges of objectoriented programming is to create a onetoone mapping between the elements in the problem space and objects in the solution how do you get an object to do useful work for you? There must be a way to make a request of the object so that it will do something, such as plete a transaction, draw something on the screen, or turn on a switch. And each object can satisfy only certain requests. The requests you can make of an object are defined by its interface, and the type is what determines the interface. A simple example might be a representation of a light bulb:The interface establishes what requests you can make for a particular object. However, there must be code somewhere to satisfy that , along with the hidden data, prises the implementation. From a procedural programming standpoint, it’s not that plicated. A type has a function associated with each possible request, and when you make a particular request to an object, that function is called. This process is usually summarized by saying that you “send a message” (make a request) to an object, and the object figures out what to do with that message (itexecutes code).Here, the name of the type/class is Light, the name of this particular Light object is lt, and the requests that you can make of a Light object are to turn it on, turn it off, make it brighter, or make it dimmer. You create a Light object by defining a “reference” (lt) for that object and calling new to request a new object of that type. To send a message to the object, you state the name of the object and connect it to the message request with a period (dot). From the standpoint of the user of a predefined class, that’s pretty much all there is to programming with objects. The diagram shown above follows the format of the Unified Modeling Language (UML). Each class is represented by a box, with the type name in the top portion of the box, any data members that you care to describe in the middle portion of the box, and the member functions (the functions that belong to this object, which receive any messages 大連交通大學(xué) 2020 屆本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 5 you send to that object) in the bottom portion of the box. Often, only the name of the class and the public member functions are shown in UML design diagrams, and so the middle portion is not shown. If you’re interested only in the class name, then the bottom portion doesn’t need to be shown, either. The hiddenimplementation It is helpful to break up the playing field into class creators (those who create new data types) and client programmers3 (the class consumers who use the data types in their applications). The goal of the client programmer is to collect a toolbox full of classes to use for rapid application development. The goal of the class creator is to build a class that exposes only what’s necessary to the client programmer and keeps everything else hidden. Why? Because if it’s hidden, the client programmer can’t use it, which means that the class creator can change the hidden portion at will without worrying about the impact