Page 166 - DCAP310_INTRODUCTION_TO_ARTIFICIAL_INTELLIGENCE_AND_EXPERT_SYSTEMS
P. 166

Introduction to Artificial Intelligence & Expert Systems




                    Notes              The concept of data classes allows a programmer to create any new data type that is not
                                       already defined in the language itself.
                                   In programming languages, an object is the composition of nouns (like data such as numbers,
                                   strings, or variables) and verbs.

                                   Object-oriented Programming takes a Radically Different Approach

                                   An object-oriented program may be viewed as a collection of interacting objects, as opposed to
                                   the conventional model, in which a program is seen as a list of tasks (subroutines) to perform. In
                                   OOP, each object is capable of receiving messages, processing data, and sending messages to
                                   other objects. Each object can be viewed as an independent “machine” with a distinct role or
                                   responsibility. Actions (or “methods”) on these objects are closely associated with the object.
                                   For example, OOP data structures tend to “carry their own operators around with them” (or at
                                   least “inherit” them from a similar object or class)—except when they must be serialized.
                                   Simple, non-OOP programs may be one “long” list of commands. More complex programs
                                   often group smaller sections of these statements into functions or subroutines—each of which
                                   might perform a particular task. With designs of this sort, it is common for some of the program’s
                                   data to be ‘global’, i.e., accessible from any part of the program.



                                     Did u know? As programs grow in size, allowing any function to modify any piece of data
                                     means that bugs can have wide-reaching effects.
                                   In contrast, the object-oriented approach encourages the programmer to place data where it is
                                   not directly accessible by the rest of the program. Instead, the data is accessed by calling specially
                                   written functions, commonly called methods, which are bundled in with the data. These act as
                                   the intermediaries for retrieving or modifying the data they control. The programming construct
                                   that combines data with a set of methods for accessing and managing those data is called an
                                   object. The practice of using subroutines to examine or modify certain kinds of data was also
                                   used in non-OOP modular programming, well before the widespread use of object-oriented
                                   programming.
                                   An object-oriented program usually contains different types of objects, each corresponding to a
                                   particular kind of complex data to manage, or perhaps to a real-world object or concept such as
                                   a bank account, a hockey player, or a bulldozer. A program might contain multiple copies of
                                   each type of object, one for each of the real-world objects the program deals with. For instance,
                                   there could be one bank account object for each real-world account at a particular bank. Each
                                   copy of the bank account object would be alike in the methods it offers for manipulating or
                                   reading its data, but the data inside each object would differ reflecting the different history of
                                   each account.
                                   Objects can be thought of as encapsulating their data within a set of functions designed to ensure
                                   that the data are used appropriately, and to assist in that use. The object’s methods typically
                                   include checks and safeguards specific to the data types the object contains. An object can also
                                   offer simple-to-use, standardized methods for performing particular operations on its data,
                                   while concealing the specifics of how those tasks are accomplished. In this way, alterations can
                                   be made to the internal structure or methods of an object without requiring that the rest of the
                                   program be modified. This approach can also be used to offer standardized methods across
                                   different types of objects. As an example, several different types of objects might offer print
                                   methods. Each type of object might implement that print method in a different way, reflecting
                                   the different kinds of data each contains, but all the different print methods might be called in
                                   the same standardized manner from elsewhere in the program. These features become especially




          160                               LOVELY PROFESSIONAL UNIVERSITY
   161   162   163   164   165   166   167   168   169   170   171