WEEK 2 – ABSTRACTION ANDENCAPSULATIONProblem ModelABSTRACTIONTwo of the most important types of abstraction arethe following:Division into parts: Has-A abstractionDivision into specialization: Is-AabstractionABSTRACTIONAbstraction – recognizing and focusing on the important characteristics of a situation or object, ignoring allthe unessential details. E.g. a roadmap represents those features of a given geographic area relevant to someone trying tonavigate with the map, major roads and places of interest, obstacles such as major bodies of water, andso on. A roadmap can’t include every building, tree, street sign, etc. that physically exists in the real world.Abstraction is a general concept in computer science and means disregarding the details of animplementation and focusing instead on the ideal being represented are hidden (i.e. encapsulated), howeverthe object is used through a well-defined interface.Data abstraction leads to an abstract data type (ADT). ADTs are objects whose implementation isencapsulated. For example, when you use a floating point number in a program you don’t really careexactly how it is represented inside the computer, provided it behaves in a known manner.ADTs should be able to be used independent of their implementation meaning that even if theimplementation changes the ADT can be used without modification. Most people would be unhappy if theytook their car to the garage for a service and afterwards the mechanic said “She’s running lovely now, butyou’ll have to use the pedals in reverse”. If this were the case the car would not be an ADT. However, thereality is that we can take a car to a garage for a major overhaul (which represents a change ofimplementation) and still drive it in exactly the same way afterwards.Abstraction as the Basis for Software DevelopmentWhen pinning down the requirements for an information systemsdevelopment project, we typically start by gathering details about thereal-world situation on which the system is to be based. These details areusually a combination of Those that are explicitly offered to us as we interview the intended users of the system,and Those that we otherwise observeWe must make a judgment call as to which of these details are relevantto the system’s ultimate purpose. This is essential, because we can’tautomate them all! To include too much detail is to overly complicate theresultant system, making it that much more difficult to design, program,test, debug, document, maintain, and extend in the future.Modelling and abstraction go hand in hand because a model isessentially a physical or graphical portrayal of an abstraction; before wecan model something effectively, we must have determined the essentialdetails of the subject to be modelledTHINKING METHODOLOGYInduction (Abstract) From specialization to generalization From different dogs to create the word “dog”DogTHINKING METHODOLOGYDeduction(infer) From generalization to specialization From the word “dog” you have learnt to know an animal is or not adog. DOG THE TWO STEPS OF OBJECT ORIENTEDPROGRAMMINGMaking Classes: Creating, extending or reusing abstract data types.Making Objects interact: Creating objects from abstract data typesand defining their relationships.7CLASS DIAGRAM – UMLDESIGN METHODOLOGIESFunctional decomposition (Top-down) The whole system is characterized by a single function, and then the function isdecomposed into a set of functions in a process of stepwise refinement.Functional composition (Bottom-up) You can have different components of functions such as that from a function library You can compose them into a module with a more significant functionFUNCTIONAL (DE)COMPOSITION Also known as top-down development Widely deemed to be a “good thing” Regard thing to be developed as a hierarchy State top level, and decomposing into smaller functions. Decomposition continues until code level. Modules with well-defined semantics that can be directly implemented Data plays a secondary role Does not necessarily reflect the states of abstraction in the application.OBJECT-ORIENTATIONIt is a kind of thinking methodology Everything in the world is an object; Any system is composed of objects (certainly a system is also an object); The evolution and development of a system is caused by the interactions among the objectsinside or outside the systemEVERYTHING IN THE WORLD IS ANOBJECTA flower, a tree, an animalA student, a professorA desk, a chair, a classroom, a buildingA university, a city, a countryThe world, the universeA subject such as OOP, C, Math, History, …ANY SYSTEM IS COMPOSED OF OBJECTSA law systemA cultural systemAn educational systemAn economic systemAn Information systemA computer systemTHE DEVELOPMENT OF A SYSTEM ISCAUSED BY THE INTERACTIONSICON College is developed by the interactions among: students lecturers staff Tesco staff whitechapel Natwest bankInside ICONOutside ICONDESIGN METHODOLOGIESObject-Orientation is one of the computational thinkingmethodologies.Object-Orientation is a kind of design methodology Objects are the building blocks of the program(interface object(editor, menu, file,etc), data managing object(db), etc.). Objects represent real-world abstractions within the application.DESIGN METHODOLOGIESObject-orientation supports both induction: objects -> a class This needs the tools for OOA/OOD and deduction: a class ->objects This needs the programmers to learn about the classlibrary.DESIGN METHODOLOGIESObject-orientation supports both Top-down: from a superclass to subclasses; complex objects to simple objects. Bottom-up: from subclasses to a superclass Simple objects to complex objectsABSTRACT DATA TYPES (ADTS)A set of data values and associated operations that are preciselyspecified independent of any particular implementation.Come with Modular Programming Abstraction Model Properties of Abstract Data Types Abstract Data Types and Object-OrientationABSTRACTION: HANDLING PROBLEMSA process of generalization by reducing the information content of aconcept or an observable phenomenon, typically in order to retain onlyinformation which is relevant for a particular purpose.Try to understand the problem to separate necessary from unnecessarydetails: You try to obtain your own abstract view, or model, of the problem.This process of modeling is called abstraction.HAS-A ABSTRACTIONDivision into parts takes a complex system, and divides into componentparts, which can then be considered in isolation. Characterized bysentences that have the words “has-a”A car has-a engine, and has-a transmissionA bicycle has-a wheelA window has-a menu barAllows us to drop down a level of complexity when we consider thecomponent in isolation.IS-A ABSTRACTIONIs-a abstraction takes a complex system, and views it as an instance ofa more general abstraction. Characterized by sentences that have thewords “is-a”A car is a wheeled vehicle, which is-a means of transportationA bicycle is-a wheeled vehicleA pack horse is-a means of transportationAllows us to categorize artifacts and information and make itapplicable to many different situations.MODELA model is an abstraction or conceptual object used in the creationof a predictive formula or a solution.A model defines an abstract view to the problem and focuses onlyon problem related stuff and that you try to define properties: the data which are affected; the operations which are identified;ADT is a kind of Model.ABSTRACT DATA TYPES(ADT)•Abstract data types are a partial solution to models•ADT defines the interface to a data abstraction withoutspecifying implementation detail.PROPERTIES OF ADTWith abstraction, you create (1) a well-defined entity whichcan be properly handled.These entities define (2) the data structure of a set of items. For example, each administered employee has a name, date of birthand social number….PROPERTIES OF ADT(CONT’D)The data structure can only be (3) accessed with defined operations. This set of operations is called interface and is exported by the entity.An entity with the properties just described is called an abstract datatype (ADT).InterfaceOperationsAbstract Data StructureAbstractData TypeADTDEFINITION (ADT)ADT is characterized by the following properties: 1. It exports a type. 2. It exports a set of operations. This set is called interface. 3. Operations of the interface are the only access mechanisms to the type’s data structure. 4. Axioms and preconditions define the application domain of the type.EXAMPLE: ADT LISTType List.The interface to instances of type List is defined by theinterface definition file.Operations: insert, get, append, delete,search,…ENCAPSULATIONEncapsulation refers to the process of hiding or encapsulating theimplementation details of an object. A washing machine is a goodexample of an encapsulated object. We know that inside a washingmachine are a whole series of complex electronics, however, we don’tneed to be able to understand them to wash our clothes.Encapsulation is the idea that data and the functions that manipulate thatdata are kept together.Encapsulation is achieved with the classClasses contain member variables that are used to hold the state of anobject—brightness, contrast, hue—and member functions (also known asmethods) that describe the behavior or operations that can be performedon the object: turn on, turn off, or change the channel. They also are asource of events, which notify clients on the current affairs of the object.Classes use encapsulation to enforce an abstractionENCAPSULATIONThis was one of the disadvantages of procedural programming; theuser of the procedure could break the procedure by giving it thewrong type of data.Encapsulation hides the properties, some methods, all methodimplementation details of an object from the outside. For example, the velocity of a car cannot be magically changed,we have to press the accelerator or brake (methods that we don’tneed to know the details of), in this respect the velocity of the caris hidden from outside interference, but can be changed by visiblemethodsENCAPSULATION(1)Combine the data and the operationsEnclosing of both variables and functionsKeep details of the data and operations from the usersof the ADTOnce you have created an ADT for complex numbers,say Complex, you can use it in the same way like wellknown data types such as integers.ENCAPSULATION(2)Allows ModularityControlled access to dataSeparates implementation from interfaceIt extends the built-in types


Leave a Reply

Your email address will not be published. Required fields are marked *