Free Essay

4 Pilars of Object Oriented Design

In:

Submitted By Carmz
Words 2333
Pages 10
De La Salle University-Dasmariñas College of Engineering, Architecture and Technology Engineering Department- CPE

FOUR PILARS OF OBJECT ORIENTED DESIGN
HOMEWORK NO.3

Submitted By:
Depone, Carmela R.
CPE52

Submitted To:
Mr. Dwight Sabio
Instructor

Date Submitted:
August 4, 2014

ABSTRACTION
A model of a complex system that includes only the details essential to perspective of the viewer of the system or Only the characteristics of the system that are essential to the problem being studied are modelled; minor or irrelevant details are ignored.
Example and Explanation * An abstraction is a model of a complex system that includes only the essential details. * Abstractions are the fundamental way that we manage complexity. * Different viewers use different abstractions of a particular system. * Thus, while we see a car as a means of transportation, the automotive engineer may see it as a large mass with a small contact area between it and the road.

What does abstraction have to do with software development? * The programs we write are abstractions. * A spreadsheet program used by an accountant models the books used to record debits and credits. * An educational computer game about wildlife models an ecosystem. * Writing software is difficult because both the systems we model and the processes we use to develop the software are complex. * One of our major goals is to convince you to use abstractions to manage the complexity of developing software.
Advantages / Pros * Helps to manage the complexity of a large system. * Support our quality goals of modifiability and reusability. * Most modifications can be localized to just a few modules. * Supports the creation of generic modules that can be used in other systems.
Application / Use * Major application of Abstraction is basically to deal with the complexity of the system. * In other words we can say that we use abstractions to simply our work.
Reference
[1] Abstraction, Updated last April, 2014, Available: http://guruzon.com/1/oop-concepts/abstraction/what-is-abstraction-example-tutorial-characteristic-how#Explanation

ENCAPSULATION
The process of packaging your program, dividing each of its classes into two distinct parts: the interface and the implementation.
By combining the attributes and methods in the same entity, which in OO parlance is called encapsulation? * One of the primary advantages of using objects is that the object need not reveal all its attributes and behaviors. * In good OO design (at least what is generally accepted as good), an object should only reveal the interfaces that other objects must have to interact with it.
Details not pertinent to the use of the object should be hidden from all other objects. * Encapsulation is defined by the fact that objects contain both the attributes and behaviors.
Example, Data hiding is a major part of encapsulation * For example, an object that calculates the square of a number must provide an interface to obtain the result. * However, the internal attributes and algorithms used to calculate the square need not be made available to the requesting object. * Robust classes are designed with encapsulation in mind. * Encapsulating the data and behavior into a single object is of primary importance in OO development. * A single object contains both its data and behaviors and can hide what it wants from other objects.
Why Encapsulation Is Fundamental to OO
Encapsulation is really the fundamental concept of OO because Whenever the interface/implementation paradigm is covered, we are really talking about encapsulation. * The basic question is what in a class should be exposed and what should not be exposed, This encapsulation pertains equally to data and behaviour. * When talking about a class, the primary design decision revolves around encapsulating both the data and the behaviour into a well-written class.
How Inheritance Weakens Encapsulation? * Encapsulation is so fundamental to OO & Inheritance is also considered one of the three primary OO concepts. However, in one way, inheritance actually breaks encapsulation! * As already mentioned, Encapsulation is the process of packaging classes into the public interface and the private implementation. * In essence, a class hides everything that is not necessary for other classes to know about. * It makes a case that when using inheritance, Encapsulation is inherently weakened within a class hierarchy, Because it introduces a specific risk as Inheritance connotes strong encapsulation with other classes but weak encapsulation between a superclass and its subclasses. * The problem is that if you inherit an implementation from a super class and then change that implementation, the change from the super class ripples through the class hierarchy. * This rippling effect potentially affects all the subclasses. At first, this might not seem like a major problem; however, as we have seen, a rippling effect such as this can cause unanticipated problems. * For example, testing can become a nightmare. * But with proper implementation of Encapsulation makes testing systems easier.
Reference
[1] Encapsulation, updated last April, 2014, Available: http://guruzon.com/1/oop-concepts/encapsulation/what-is-encapsulation-example-tutorial-how-to-use

INHERITANCE
Inheritance as its name implies, involves inheriting attributes and behaviours from other classes. Inheritance represents the is-a relationship between two entities or objects. There is a true parent/child relationship and The child (or subclass) inherits directly from the parent (or super class). Remember that Composition is also as its name implies, involved building objects by using other objects.
Example
* One of the most powerful feature of Object Oriented programming is code Reusability. * Structured design provides code reuse to a certain extent hence you can write a procedure and then use it as many times as you want. * Inheritance also helps by organizing classes and factoring in commonalties of various classes. * Inheritance is a primary means of providing this functionality. * Inheritance allows a class to inherit the attributes and methods of another class.
This Inheritance UML notation example * Allows creation of brand new classes by abstracting out common attributes and behaviours. * One of the major design issues in OO programming is to factor out commonality of the various classes. * You have a Dog class and a Cat class, and each will have an attribute for eye color. * In a procedural model, the code for Dog and Cat would each contain this attribute. * In an OO design, the color attribute could be moved up to a class called Mammal along with any other common attributes and methods. * In this case, both Dog and Cat inherit from the Mammal class, as shown below:

* The Dog and Cat classes both inherit from Mammal. * This means that a Dog class actually has the following attributes: eyeColor // inherited from Mammal barkFrequency // defined only for Dogs
In the same vein, Dog object has the following methods: getEyeColor // inherited from Mammal bark // defined only for Dogs
Inheritance represents Is-a Relationships * For example there is a parent class (Shape Class) and Circle, Square and Star all inherit directly from Shape Class. * This relationship is often referred to as an is-a relationship because a circle is a shape, Square is a shape and Star is a shape. * When a subclass inherits from a super class, it can do anything that the super class can do. * In below figure, the name on each of the objects represents the Draw method for the Circle, Star and Square objects respectively. * When we design this Shape system it would be very helpful to standardize how we use the various shapes. * This way we could decide that if we want to draw a shape, No matter what shape, we will invoke a method called draw.

Advantages of Inheritance * There are two major benefits to inheritance. * The First, we can specialize existing classes (types) and write only the code that is changed. * In this way, we can reuse our existing classes (as base classes) and capitalize on the work already done. * We no longer have to "copy and paste" code. * Copying and pasting is particularly problematic because changes in one section of the code must be replicated in another—a dangerous and failure-prone model. * Instead, by using Inheritance, we can make changes in the base class that automatically update all the derived classes. * The second significant benefit of inheritance is that it allows us to treat the derived objects polymorphic ally.
Reference
[1] Inheritance, Updated last April, 2014, Available: http://guruzon.com/1/oop-concepts/inheritance-and-composition/what-is-inheritance-example-tutorial-uml-notation
POLYMORPHISM
Polymorphism means the ability to take on many forms; The term is applied both to objects and to operations. Polymorphism is tightly coupled to inheritance and is one of the most powerful advantages to object-oriented technologies. Polymorphism is a Greek word that means Many Shapes.
Polymorphism: Polymorphic object details with example * Suppose a financial company handles different subtypes of Funds, such as an Asia Fund, Domestic Fund, and so on. * Each with its own idiosyncrasies. * We model this situation using a generalized class(Fund) and a specialized class for each subtype of Fund with difference operations and states. * When the operation is actually executed, though the Fund object will take on one of many forms for example, an Asia Fund or a Domestic Fund. * In other words, the Fund object is polymorphic.
Polymorphism: Polymorphic operation details with example * Polymorphic operation - "One Operation, Many Methods". * A polymorphic operation is one whose method may take on many forms based on the class of the object carrying it out. * A polymorphic operation is one whose method may take on many forms based on the class of the object carrying it out. * Continuing with the same example, since all the Fund subtypes have to be able to accept deposits, we can define a Fund operation called accept deposit. * This operation is inherited by all the specializations. * We can also specify a method for this Fund operation that will be inherited by the specializations. * But what if one or more of the specializations for example, the Asia Fund—uses a different procedure for accepting deposits? * In this case, we can add documentation to the Asia Fund class that describes a method that overrides the one inherited from the generalized class.
For example, * The method described might involve supplementary charges. In practice, when capital investment causes a Fund to perform an accept deposit operation, the method that is used to carry out the operation will take on one of many forms. * This is what is meant by a polymorphic operation. * With polymorphic operations, the selection of the method depends on which particular class (Asia Fund, Domestic Fund, and so on) is carrying it out. * Now let's look at an Object Oriented Programming example. * By using polymorphism and grouping the Circle into a Shape category, Shape figures out that it is a Circle and knows how to print itself (see below figure):

Shape.print(); // Shape is actually a Circle
Shape.print(); // Shape is actually a Square
Polymorphism - One Interface, Many Implementations * Polymorphism means "one interface, many possible implementations."
For example, * Cars are designed with polymorphism in mind. * They all use the same interface-an accelerator pedal-to change speed, even though the internal method may differ from model to model. * The auto industry designs cars this way so that the drivers do not have to learn a new interface for each new model of car.
Two types of polymorphism 1. Static (compile time) polymorphism 2. Dynamic (run time) polymorphism
Static polymorphism means that the information required to call a function is available at compile time itself. * Hence function calls can be resolved at compile time. The exact function to call is determined by the difference in either the number or type of functions parameters. * Static polymorphism is achieved through function overloading, operator overloading and even function templates (in Java/C++). * It is always faster and efficient than dynamic polymorphism because the run time cost of function call resolution is avoided.
For example, * An employee object may have two print() methods one taking no arguments and one taking a prefix string to be displayed along with the employee data. * Given these interfaces, when the print() method is called without any arguments, the compiler, looking at the function arguments knows which function is meant to be called and it generates the object code accordingly.
Dynamic polymorphism means that the information required to call a function is not known until run time. * If a derived class needs to redefine a particular method defined in the base class, the method is declared as virtual in the base class and redefined, to fit its own needs, in the derived class. * The virtual function in the base class basically defines the interface of that function. Each derived class of the base class with virtual methods can redefine the methods with its own implementation. * A base-class reference (and pointer in case of C++) can be used to point to an object of any class derived from that base. * When a base reference or pointer points to a derived object that contains a virtual function, the exact function to call is determined based upon the type of object calling the method at runtime. * Thus, when different derived objects are pointed to by the base class reference or pointer, appropriate versions of the virtual function are executed. * Since the call is resolved at runtime, dynamic polymorphism results in slightly slower execution of the program.
For example, * Consider an application that serializes and de-serializes different types of documents. * We can have ‘Document’ as the base class and different document type classes deriving from it. E.g. XMLDocument, Word Document, etc. * Document class will define ‘Serialize ()’ and ‘De-serialize ()’ methods as virtual and each derived class will implement these methods in its own way based on the actual contents of the documents. * When different types of documents need to be serialized/de-serialized, the document objects will be referred by the ‘Document’ class reference (or pointer) and when the ‘Serialize ()’ or ‘De-serialize ()’ method are called on it, appropriate versions of the virtual methods are called.
Reference
[1] Polymorphism, Updated last April, 2014, Available: http://guruzon.com/1/oop-concepts/polymorphism/what-is-polymorphism-example-tutorial-uml-diagram-notation

Similar Documents

Premium Essay

Tools for Business

...Mid Sweden University The Department of Information Technology and Media (ITM) Author: Katarina Lundqvist, kalu9700@student.miun.se Study program: Master of Science in Engineering – Computer Engineering, 270 higher education credits Examiner: Tingting Zhang, tingting.zhang@miun.se Tutor: Aron Larsson, aron.larsson@miun.se Tutor: Mats Olsson, mats.olsson@sogeti.se Scope: 20102 words inclusive of appendices Date: 2010-03-17 M.Sc. Thesis in Computer Engineering AV, 30 higher education credits Tools for Business Intelligence A comparison between Cognos 8 BI, Microsoft BI and SAP BW/NetWeaver Katarina Lundqvist Abstract 2010-03-17 Tools for Business Intelligence A comparison between Cognos 8 BI, Microsoft BI and SAP BW/NetWeaver Katarina Lundqvist Abstract The aim of the thesis was to conduct a general study of Business Intelligence and BI systems followed by a comparison of Cognos 8 BI, Microsoft BI and SAP BW/NetWeaver. The goal was to distinguish similarities and differences between the tools regarding technique, cost, usability and educational need and to provide a mapping for different customer situations. The method consisted of a theoretical study followed by a practical part including development, testing and interviews. The comparison showed that SAP and Microsoft both use the client/server model while Cognos is an integrated web-based system built on SOA. SQL Server can only be installed on Windows while BW and Cognos also support...

Words: 25350 - Pages: 102

Premium Essay

Bahrain

...Journal of Knowledge Management Knowledge management in organizations: examining the interaction between technologies, techniques, and people Ganesh D. Bhatt Article information: To cite this document: Ganesh D. Bhatt, (2001),"Knowledge management in organizations: examining the interaction between technologies, techniques, and people", Journal of Knowledge Management, Vol. 5 Iss 1 pp. 68 - 75 Permanent link to this document: http://dx.doi.org/10.1108/13673270110384419 Downloaded on: 28 September 2014, At: 06:01 (PT) References: this document contains references to 20 other documents. To copy this document: permissions@emeraldinsight.com The fulltext of this document has been downloaded 11983 times since 2006* Downloaded by University of Bahrain At 06:01 28 September 2014 (PT) Users who downloaded this article also downloaded: Karl M. Wiig, (1997),"Knowledge Management: An Introduction and Perspective", Journal of Knowledge Management, Vol. 1 Iss 1 pp. 6-14 Rory L. Chase, (2007),"The expanding world of knowledge management", Journal of Knowledge Management, Vol. 11 Iss 3 pp. Roelof P. uit Beijerse, (1999),"Questions in knowledge management: defining and conceptualising a phenomenon", Journal of Knowledge Management, Vol. 3 Iss 2 pp. 94-110 Access to this document was granted through an Emerald subscription provided by 382676 [] For Authors If you would like to write for this, or any other Emerald publication, then please use our Emerald for Authors...

Words: 9761 - Pages: 40

Free Essay

Study on Iron Ore Slags

...2007:224 CIV M ASTER’S TH E SI S Study of the reactions between iron ore slag and refractories Julien Zimmermann MSc PrograMMeS in engineering Materials Technology (eeigM) Luleå University of Technology Department of Applied Physics and Mechanical Engineering Division of Material Mechanics 2007:224 CIV • ISSN: 1402 - 1617 • ISRN: LTU - EX - - 07/224 - - SE Summary: For the fabrication of iron ore pellets at LKAB (Luossavaara-Kiirunavaara AB), one of the methods used is to sinter the pellets in a rotary kiln. This Kiln has a drift temperature of 1250°C in average. During this process a coating, causing the wear of the refractories materials, is formed, inducing expensive maintenance periods. The aim of this work is to find the reaction that takes place between the Slag and the bricks, in order to find the parameters that have to be changed to improve the bricks lifetime in the kiln. The use of bricks with higher alumina content is one of the solutions, but it is expensive. The influence of Alkalis and especially Na2O has been studied before in inert atmosphere. In this work it will be studied in air as well as the influence of the alumina content of the brick. Experiments were performed in air atmosphere, using powder samples that have been compressed into pellets. The devices used to characterize the reaction and the product of the reaction were: Kanthal furnace, X-ray diffraction (XRD), dilatometer, differential scanning calorimetry and thermogravimetry (DSC/TG)...

Words: 20108 - Pages: 81

Premium Essay

Poverty Diemnsions

...JOSÉ LUIS MACHINEA Executive Secretary ALICIA BÁRCENA Deputy Executive Secretary Economic Commission for Latin America and the Caribbean economic commission for latin america and the caribbean C E P A L Review NUMBER 85 APRIL 2005 SANTIAGO, CHILE OSCAR ALTIMIR Director REYNALDO BAJRAJ Deputy Director The CEPAL Review was founded in 1976 and is published three times a year by the United Nations Economic Commission for Latin America and the Caribbean, which has its headquarters in Santiago, Chile. The Review, however, has full editorial independence and follows the usual academic procedures and criteria, including the review of articles by independent external referees. The Review is distributed to universities, research institutes and other international organizations, as well as to individual subscribers, and is also consulted extensively on the Internet. The purpose of the Review is to contribute to the discussion of socio-economic development issues in the region by offering analytical and policy approaches and articles by economists and other social scientists working both within and outside the United Nations. Accordingly, the editorial board of the Review extends its readers an open invitation to submit for publication articles analysing various aspects of economic and social development in Latin America and the Caribbean. The opinions expressed in the signed articles are those of the authors and do not necessarily reflect the views of the...

Words: 105806 - Pages: 424

Free Essay

Importance of Socialization

...W O M E N ’ S C O M M I S S I O N for refugee women & children w U N TA P P E D P OT E N T I A L : Adolescents affected by armed conflict A review of programs and policies U N TA P P E D P OT E N T I A L : Adolescents affected by armed conflict A review of programs and policies Wo m e n ’s C o m m i s s i o n f o r R e f u g e e Wo m e n & C h i l d r e n N e w Yo r k W O M E N ’ S C O M M I S S I O N for refugee women & children Copyright © January 2000 by Women’s Commission for Refugee Women and Children All rights reserved. Printed in the United States of America ISBN: 1-58030-000-6 Women’s Commission for Refugee Women and Children 122 East 42nd Street New York, NY 10168-1289 tel. 212.551.3111 or 3088 fax. 212.551.3180 e-mail: wcrwc@intrescom.org www.intrescom.org/wcrwc.html w cover photographs © Rachel K. Jones, Marc Sommers, Sarah Samson, Holly Myers, Anne-Sophie Rosette, International Rescue Committee M I S S I O N S TAT E M E N T The Women’s Commission for Refugee Women and Children seeks to improve the lives of refugee women and children through a vigorous program of public education and advocacy, and by acting as a technical resource. The Commission, founded in 1989 under the auspices of the International Rescue Committee, is the only organization in the United States dedicated solely to speaking out on behalf of women and children uprooted by armed conflict or persecution. Acknowledgments The Women’s Commission expresses its sincere...

Words: 101041 - Pages: 405

Free Essay

Jezz Bezos

...Begin Reading Table of Contents Photos Newsletters Copyright Page In accordance with the U.S. Copyright Act of 1976, the scanning, uploading, and electronic sharing of any part of this book without the permission of the publisher is unlawful piracy and theft of the author’s intellectual property. If you would like to use material from the book (other than for review purposes), prior written permission must be obtained by contacting the publisher at permissions@hbgusa.com. Thank you for your support of the author’s rights. For Isabella and Calista Stone When you are eighty years old, and in a quiet moment of reflection narrating for only yourself the most personal version of your life story, the telling that will be most compact and meaningful will be the series of choices you have made. In the end, we are our choices. —Jeff Bezos, commencement speech at Princeton University, May 30, 2010 Prologue In the early 1970s, an industrious advertising executive named Julie Ray became fascinated with an unconventional public-school program for gifted children in Houston, Texas. Her son was among the first students enrolled in what would later be called the Vanguard program, which stoked creativity and independence in its students and nurtured expansive, outside-the-box thinking. Ray grew so enamored with the curriculum and the community of enthusiastic teachers and parents that she set out to research similar schools around the state with an eye toward writing a book about...

Words: 120163 - Pages: 481