180 likes | 201 Views
Concepts in Object-Oriented Programming. Model -B ased P rogramming and V erification. Introduction. The deep understanding of object-oriented concepts (independently of a given programming language) is necessary .
E N D
Concepts in Object-Oriented Programming Model-Based Programming and Verification
Introduction • The deep understanding of object-oriented concepts (independently of a given programming language) is necessary. • The following features make a system object-oriented according to Wegner*: data abstraction, abstract data type and type inheritence • Other important notions areknowledge-sharing, encapsulation and polymorphism. Wegner, P.: Classification in Object-Oriented Systems, SIGPLAN Notices, Vol 21, No 10, 1986, pp. 173-183
Introduction • Object-oriented programming (OOP) is a programming paradigm that uses objects and their interactions to design applications and computer programs. It isbased on several techniques, including inheritance, modularity, polymorphism, and encapsulation. It was not commonly used in mainstream software applicationdevelopment until the early 1990s. Many modern programming languages now support OOP.
History • Object-oriented programming roots reach all the way back to the 1960s, when the nascent field of software engineering had begun to discuss the idea of asoftware crisis. As hardware and software became increasingly complex, researchers studied how software quality could be maintained. • Object-orientedprogramming was deployed to address this problem by strongly emphasizing modularity (discrete units of programming logic) and reusability in software.
Today… • More recently, a number of languages have emerged that are primarily object-oriented yet compatible with procedural methodology, such as Python and Ruby. • Besides Java, probably the most commercially important recent object-oriented languages are Visual Basic .NET and C# designed for Microsoft's .NETplatform. • Just as procedural programming led to refinements of techniques such as structured programming, modern object-oriented software design methods includerefinements such as the use of design patterns, design by contract, and modeling languages (such as UML).
Fundamental concepts - Class • A class defines the abstract characteristics of an object, including the characteristics (its attributes, fields or properties) and behaviors (methods or features) of that object. • Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. • The code for a class should be relatively self-contained. Collectively, the properties and methods defined by a class are called members.
Object • An object is a particular instance of a class. The class of Birds defines all possible birds by listing the characteristics and behaviors they can have; the object Crow is a subcategory of Birds with particular versions of the characteristics. • The set of values of the attributes of a particular object is called its state. • The object consists of state and the behavior that is defined in the object's class.
Method • An object's abilities. William, being a Bird, has the ability to fly. • He may have other methods as well, for example drink() or eat(). • Within the program, using a method should only affect one particular object; all Birds can fly, but you need one particular bird to do the activity.
Types of inheritence • For example, specialization, reusability. • Specialization is represented by subtypes (subclasses). • Reusability is code sharing. • This way they are different on the level of abstraction. Specialization (specification level), code sharing (implementation level).
Inheritance • Subclasses are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own. • For example, the class Bird might have subclasses called Crow, Hawk, and Eagle. In this case, William would be an instance of the Hawk subclass. Suppose the Bird class defines a method called fly() and a property called furColor. Each of its subclasses will inherit these members, meaning that the programmer only needs to write the code for them once. Subclasses can also add new members. • Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Horses and Humans, and a Centaur object could be created from these two which inherits all the (multiple) behavior of horses and humans. This is not always supported, as it can be hard both to implement and to use well.
Encapsulation • Encapsulation conceals the functional details of a class from objects that send messages to it. • Encapsulation is achievedby specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those membersaccessible to that class. • The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that arelikely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. Members are often specified as public, protected or private,determining whether they are available to all classes, subclasses or only the defining class.
Abstraction • Abstraction is simplifying complex reality by modeling classes appropriate to the problem, and working at the most appropriate level of inheritance for agiven aspect of the problem. • Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many morecomponents. To build the Carclass, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receivemessages from them, and perhaps make the different objects composing the class interact with each other.
Abstraction I. • There are several kinds of abstraction (e.g. a procedure is an abstraction for a sequence of instructions, a class is an abstraction for a collection of objects, a module is a set of named abstractions). • Abstraction provides means for structuring software, controlling interactions between parts of the software, and verifying proper assembly. • Most software environments impose some restrictions on the use of abstractions.
Abstraction II. • The process of modeling the problem domain is known as abstraction as well. • Abstraction concentrates on the essential aspects of an entity while ignoring its nonessential properties (fundamental part of object-oriented technology). • Use of abstraction preserves the freedom to make decisions as long as possible by avoiding premature commitments to details. • Object-oriented methodologies model a system by using the objects (entities) and interactions discovered in the system. • In the object-oriented approach, entities include both data and their associated functionality. These two items are bound together in a structure called class.
Polymorphism • Polymorphism allows you to treat derived class members just like their parent class's members. More precisely, Polymorphism in object-orientedprogramming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to anappropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. • Overloading Polymorphism is the useof one method signature, or one operator such as "+", to perform several different functions depending on the implementation. The "+" operator, forexample, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such asInteger and Double, are expected to add together properly in an OOP language. The language must therefore overload theconcatenation operator, "+", towork this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at leastsome level of overloading polymorphism. • Many OOP languages also support Parametric Polymorphism, where code is written without mention of anyspecific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be usedwith many different types of objects [4].
Data types I. • An abstract data type is a class of data types that is closed under renaming of data domains, items and operations, and hence independent of a concrete representation. • A data type is a collection of data domains, designated basic data items, and operations on these domains such that all data items of data domains can be generated from the basic data items by using the operations (data domains are assumed to be countable).
Data types II. • From a mathematical point of view data types are algebras. • It is often assumed that all data items of a data type are generated by a given set of the operations of that data type. These operations are called constructors. • Another set of operations are called non-constructors or selectors because these operations can be used to select parts of an object. • The syntactic structure of an abstract data type D is determined by its signature, the semantics of D is based on the notion of a computation structure, (e.g. a many-sorted algebra A of the given signature).