Object Oriented Programming - WordPress

2y ago
44 Views
4 Downloads
812.67 KB
39 Pages
Last View : 2m ago
Last Download : 3m ago
Upload by : Luis Wallis
Transcription

1 Pagecs304Object oriented programmingFAQsWhat is Abstraction?Answer: The importance of abstraction is derived from itsability to hide irrelevant details and from the use of names toreference objects. Abstraction is essential in theconstruction of programs. It places the emphasis on what anobject is or does rather than how it is represented or how itworks. Thus, it is the primary means of managing complexity inlarge programs.Question:What is a Class Diagram?Answer: A class diagrams are widely used to describe thetypes of objects in a system and their relationships. Classdiagrams model class structure and contents using designelements such as classes, packages and objects.Question:What is Method Overriding?

2 PageAnswer: Method overriding is a language feature that allowsa subclass to override a specific implementation of a methodthat is already provided by one of its super-classes. Asubclass can give its own definition of methods but need tohave the same signature as the method in its super-class. Thismeans that when overriding a method, the subclass's methodhas to have the same name and parameter list as the superclass's overridden method.Question:What is Operator Overloading?Answer: The operator overloading is a specific case ofpolymorphisms in which some or all of operators like , - or are treated as polymorphic (multi) functions and as such havedifferent behaviors depending on the types of its arguments.Question:What is Method Overloading?Answer: The method overloading is the ability to defineseveral methods (in same class) all with the same name butdifferent on the basis of i) number of parameters ii) types ofparameters.Question:What are Polymorphisms?

3 PageAnswer: Polymorphism is a generic term that means 'manyshapes'. More precisely Polymorphism means the ability torequest that the same operations be performed by a widerange of different types of things.Question:What is Inheritance?Answer: Ability of a new class to be created, from anexisting class by extending it, is called inheritance.Question:What is a base class?Answer: When inheritance is used to create a new class fromanother, the new class is called the subclass or derived class,and the class from which it was derived is called the baseclass.Question:What is a concrete class?Answer: A concrete class is one that can be used to directlycreate, or instantiate objects, unlike an abstract base classwhich can only be used as a base class for other classes whicheventually lead to concrete classes

4 PageQuestion:What are data members?Answer: Objects are miniature programs, consisting of bothcode and data. The code consists of a series of memberfunctions. The data items are called data members.What is a constructor?Answer: Objects are complete, miniature programs and, likeany good programs, have well defined initialization andtermination phases. They have special routines (i.e. memberfunctions) to look after this. The initialization routine is calledthe constructor, and C ensures that every object is properlyinitialized by calling its constructor. The designer of theobject can have more than one constructor, a situation calledoverloading and then the compiler will select between themdepending on exactly what arguments are passed to theconstructor function. However, there must always be adefault constructor, to be used when no information issupplied.Question:What is a destructor?Answer: The termination routine is called the destructor, andC will provide a default if none is supplied. If, during the

5 Pagelifetime of the object, it uses heap memory then the designerof the object must provide a destructor function to releasesuch memory to avoid a memory leak.Question:What is global variable?Answer: Global variables can be accessed throughout aprogram. Another way to put this is to say they have globalscope.Question:What is local variable?Answer: Local variables can only be accessed within thefunction, or more specifically the compound statement inwhich they are declared. Another way to put this is to saythey have local scope.Question:What is a null pointer?Answer: A null pointer is a pointer that is currently pointingto nothing. Often pointers are set to zero to make them nullpointers or tested against zero to see if they are null or not.Question:What is a pointer?Answer: A pointer is a variable that holds the address ofanother variable or object.Question:What is meant by protected?

6 PageAnswer: The protected keyword in the class statementmeans that the following members of the class are notavailable to users of the objects of the class, but can be usedby any subclass that inherits from it, and consequently formspart of its implementation.Question:What is OOP?Answer: The object-oriented programming is commonly knownas OOP. Most of the languages are developed using OOPconcept. Object-oriented programming (OOP) is aprogramming concept that uses "objects" to develop a system.An object hides the implementation details and exposes onlythe functionalities and parameters it requires to its client.Here also an object shares the same concept as that of a bike.While driving a motor bike, we are unaware of itsimplementation details such as how it is developed, internalworking of gears etc.? We know only the functions or actionsit can perform.Question:What are the various elements of OOP?Answer: Various elements of OOP are: Object Class MethodEncapsulation Information Hiding Inheritance PolymorphismQuestion:What are the characteristics of Object-Oriented programming language?

7 PageAnswer: Some key features of the Object Orientedprogramming are: Emphasis on data rather than procedurePrograms are divided into entities known as objects DataStructures are designed such that they characterize objectsFunctions that operate on data of an object are tied togetherin data structures Data is hidden and cannot be accessed byexternal functions Objects communicate with each otherthrough functions New data and functions can be easily addedwhenever necessary Follows bottom up design in program des.What are the basic Concepts used in the Object-OrientedProgramming language?Answer: Object Class Data Abstraction and EncapsulationPolymorphism Inheritance Message passing Dynamic bindingQuestion:Technology)What Is an Object? (Object-Oriented

8 PageAnswer: There are many definitions of an object, such asfound in [Booch 91, p77]: "An object has state, behavior, andidentity; the structure and behavior of similar objects aredefined in their common class; the terms instance and objectare interchangeable". This is a "classical languages" definition,as defined in [Coplien 92, p280], where "classes play a centralrole in the object model", since they do not inprototyping/delegation languages. "The term object was firstformally applied in the Simula language, and objects typicallyexisted in Simula programs to simulate some aspect of reality"[Booch 91, p77]. Other definitions referenced by Boochinclude Smith and Tockey: "an object represents an individual,identifiable item, unit, or entity, either real or abstract, witha well-defined role in the problem domain." and [Cox 91]:"anything with a crisply defined boundary" (in context, this is"outside the computer domain". A more conventional definitionappears on pg 54). Booch goes on to describe these definitionsin depth. [Martin 92, p 241] defines: "An "object" is anythingto which a concept applies", and "A concept is an idea or notionwe share that applies to certain objects in our awareness".[Rumbaugh 91] defines: "We define an object as a concept,abstraction or thing with crisp boundaries and meaning for theproblem at hand." [Shlaer 88, p 14] defines: "An object is anabstraction of a set of real-world things such that:Question:What Is Object Encapsulation (Or Protection)?

9 PageAnswer: [Booch 91, p. 45] defines: "Encapsulation is theprocess of hiding all of the details of an object that do notcontribute to its essential characteristics." [Coad 91, 1.1.2]defines: "Encapsulation (Information Hiding). A principle, usedwhen developing an overall program structure, that eachcomponent of a program should encapsulate or hide a singledesign decision. The interface to each module is defined insuch a way as to reveal as little as possible about its innerworkings. [Oxford, 1986]" Some languages permit arbitraryaccess to objects and allow methods to be defined outside ofa class as in conventional programming. Simula and ObjectPascal provide no protection for objects, meaning instancevariables may be accessed wherever visible. CLOS and Adaallow methods to be defined outside of a class, providingfunctions and procedures. While both CLOS and Ada havepackages for encapsulation, CLOS's are optional while Ada'smethodology clearly specifies class-like encapsulation (Adts).However most object-oriented languages provide a welldefined interface to their objects thru classes. C has a verygeneral encapsulation/protection mechanism with public,private and protected members. Public members (member dataand member functions) may be accessed from anywhere. AStack's Push and Pop methods will be public. Private membersare only accessible from within a class. A Stack'srepresentation, such as a list or array, will usually be private.

10 P a g eProtected members are accessible from within a class and alsofrom within subclasses (also called derived classes). A Stack'srepresentation could be declared protected allowing subclassaccess. C also allows a class to specify friends (other(sub)classes and functions), that can access all members (itsrepresentation). Eiffel 3.0 allows exporting access to specificclasses.Question:What Is A Class?Answer: A class is a general term denoting classification andalso has a new meaning in object-oriented methods. Withinthe OO context, a class is a specification of structure(instance variables), behavior (methods), and inheritance(parents, or recursive structure and behavior) for objects. Aspointed out above, classes can also specify access permissionsfor clients and derived classes, visibility and member lookupresolution. This is a feature-based or intentional definition,emphasizing a class as a descriptor/constructor of objects (asopposed to a collection of objects, as with the more classicalextensional view, which may begin the analysis process).Original Aristotle a classification defines a "class" as ageneralization of objects: [Booch 91, p93] "a group, set, orkind marked by common attributes or a common attribute; agroup division, distinction, or rating based on quality, degreeof competence, or condition".

11 P a g eQuestion:What Is A Meta-Class?Answer: Meta-Class is a class' class. If a class is an object,then that object must have a class (in classical OO anyway).Compilers provide an easy way to picture Meta-Classes.Classes must be implemented in some way; perhaps withdictionaries for methods, instances, and parents and methodsto perform all the work of being a class. This can be declaredin a class named "Meta-Class". The Meta-Class can alsoprovide services to application programs, such as returning aset of all methods, instances or parents for review (or evenmodification). [Booch 91, p 119] provides another example inSmalltalk with timers. In Smalltalk, the situation is morecomplexQuestion:What Is Inheritance?Answer: Inheritance provides a natural classification forkinds of objects and allows for the commonality of objects tobe explicitly taken advantage of in modeling and constructingobject systems. Natural means we use concepts, classification,and generalization to understand and deal with thecomplexities of the real world. See the example below usingcomputers. Inheritance is a relationship between classeswhere one class is the parent base/superclass/ancestor/etc.)class of another. Inheritance provides programming byextension (as opposed to programming by reinvention [LaLonde

12 P a g e90]) and can be used as an is-a-kind-of (or is-a) relationship orfor differential programming. Inheritance can also double forassignmentQuestion:What Is the Difference Between Object-Basedand Object-Oriented?Answer: Object-Based Programming usually refers to objectswithout inheritance [Cardelli 85] and hence withoutpolymorphism, as in '83 Ada and Modula-2. These languagessupport abstract data types (Adts) and not classes, whichprovide inheritance and polymorphism. Ada95 and Modula-3;however, support both inheritance and polymorphism and areobject-oriented. [Cardelli 85, p481] state "that a language isobject-oriented if and only if it satisfies the followingrequirements: - It supports objects that are dataabstractions with an interface of named operations and ahidden local state. - Objects have an associated type. - Typesmay inherit attributes from supertypes. object-oriented data abstractions object types type inheritance Thesedefinitions are also found in [Booch 91, Ch2 and Wegner 87].[Coad 91] provides another model: Object-Oriented Classesand Objects Inheritance Communication with messages.

13 P a g eLecture 01 complete concept:To understand OOP, you must first understand whatprogramming was like before OOP.Back then, the basic definition of programming was this : aprogram is a sequence of logical instructions followed by thecomputer. And that's it. All well and good, but let's face it,it's hardly inspiring. Until now, that is. It's been hiding in thebackground for quite some time now, but OOP has finallytaken off. In an OO programming language, the emphasis isplaced far more on the data, or the 'objects' used and howthe programmer manipulates them. Before OOP, numbers weresimply an address in memory; a sequence of bytes that meantnothing. Now, however, through OOP they have become farmore than that. The program is now a solution to whateverproblem it is you have, but now it is done in the terms of theobjects that define that problem, and using functions thatwork with those objectsA Historical InterludeHundreds of years ago, in Britain (specifically England), therewas civil unrest. People were angry - the poor people to bemore specific. They noticed that some people were richerthan them, they did not like it. What to do about thisproblem? How to keep the people happy? Religion had alreadygone some of the way, but even the promise of eternal utopia

14 P a g eif the poor behaved themselves in life didn't seem to work.Capitalism already had sunk its powerful jaws into the world,and a new idea was needed to keep the masses happy. Thatidea became known as 'class'. The basis was that if everyoneunderstood their place and role in society, they would feelsecure and happy, and would not challenge the authority. Itworked. There was the upper class (who were rich), the middleclass (who were not so rich), and the poor sods class (whocould barely afford to live). Quite unfair, but nevertheless itbecame reality. What has this got to do with C you ask?Well in C , all Object Orientation comes in the form ofclasses. But enough of that; we're programmers, not socialscientists.Data typesUp to this point in your use of C , you've used only the basictypes of variables : int, float, bool, double, and so forth.These are called simple data types. However, they are verylinear in what we can 'model' with them. Let's take anexample. Let's say we wanted to represent a real life object,say a house. Obviously, we would have to examine the variousattributes of a house : the number of rooms it has, its streetnumber and whether or not it has a garden (okay, so there aremore attributes, but I won't go into them now). In C , wecould show the house like this:int number, rooms;bool garden;

15 P a g eAnd it would work fine for this particular example. Butsuppose we wanted many houses? Suppose we wanted to makethe program more complicated than this? Suppose we wantedto define our own data type to represent the house. C allowsus to do this through the use of classes.History of oop?The basis for OOP started in the early 1960s. A breakthroughinvolving instances and objects was achieved at MIT with thePDP-1, and the first programming language to use objects wasSimula 67. It was designed for the purpose of creatingsimulations, and was developed by Kristen Nygaard and OleJohan Dahl in Norway.Who invented OOP?Alan KayAlan Kay invented OOP and coined the term.What was the first OOP language?SIMULA 67 was formally standardized on the first meetingof the SIMULA Standards Group (SSG) in February 1968.Simula was influential in the development of Smalltalk andlater object-oriented programming languages.When OOP concept did first came into picture?When OOP concept did first came into picture?Explanation: OOP first came into picture in 1970's by Alan

16 P a g eand his team. Later it was used by some programminglanguages and got implemented successfully, SmallTalkwas firstlanguage to use pure OOP and followed all rulesstrictlWhy was OOP developed?It was created for making simulation programs, in which whatcame to be called objects were the most importantinformation representation. Smalltalk (1972 to 1980) isanother early example, and the one with which much of thetheory of OOP was developed.Four principles of OOP are encapsulation,data abstraction,data hiding and inheritance.Encapsulation: In technical terms, it means wrapping up ofdata and code in to a single unit(i.e Class) and also protectingthe data from outside world.There is also another term related with encapsulation is datahiding. Data hiding means hiding the data from world. Data cannot be accessed directly.Data Abstraction: Abstraction means hiding unessentialdetails from user. And providing only essential information.Inheritance: Inheriting the properties of super class insubclass. Basically subclass is more specialized one and itprovides re usability.In layman terms: For eg Mobile phone which we use everyday.Everything is wrapped inside the body of the phone. No one

17 P a g ecan access the functionality of mobile directly. To access thestuff you need object(here object is mobile)you can’t make a call without having mobile. Now what is datahiding?Data hiding means giving access to mobile in control manner.In technical terms: we use getter and setter methods. But inour mobile: Password and pattern lock are the ways ofproviding data hiding. One who knows the password, only canaccess your phone(This is called data hiding)Data hiding basically provides you security. Your phone islocked. Even if you are not having your phone nearby . youknow that it is protected.Data Abstraction: suppose you wanna make a call to your mom.What you need?Just valid number!To make a call, you never need to know the background detailshow calling is being done. (Like connecting to networkwhichever your mom is using either airtel or idea etc)So What data abstraction gives? it provides easiness to us.Inheritance: Suppose you are using android phone versionsuppose lollypop. So basically lollypop version has inherited allfunctionality of previous versions i.e kitkatwith some new functionalities.

18 P a g eSo, Lollypop version basically is specialized version of Kitkat.There is another principle also: PolymorphismIt means having same name but different functionality. Intechnical terms, function overloading, function overriding etcNow let see how polymorphism is implemented in your mobile.Every mobile has inbuilt camera. But still there are anotherapps which let us take photos like Retrica.Retrica which has different functionality but does the samework(clicking photos).So, what is OOPS (Object Oriented Programming)?Object-oriented Programming (OOP) is a programmingparadigm based on the concept of "objects", which maycontain data, in the form of fields, often known as attributes;and code, in the form of procedures, often known as methods.Here are the four principles of OOPS are : pillers of oop

19 P a g e Abstraction: Abstraction means using simpl

Answer: The object-oriented programming is commonly known as OOP. Most of the languages are developed using OOP concept. Object-oriented programming (OOP) is a programming concept that uses "objects" to develop a system. An object hides the implementation details and exposes only the

Related Documents:

method dispatch in different object-oriented programming languages. We also include an appendix on object-oriented programming languages, in which we consider the distinction between object-based and object-oriented programming languages and the evolution and notation and process of object-oriented analysis and design, start with Chapters 5 and 6;

object-oriented programming language is based on a kind of old object-oriented programming language. For example, though C language is an object-oriented programming language, it still retains the pointer which is complex but has strong function. But C# improved this problem. C# is a kind of pure object-oriented language.

The principle of object oriented programming is to combine both data and the associated functions into a single unit called a class. An object in programming means data. Data is therefore predominant in object oriented programming. The concept will become clear with examples. However, in the object oriented paradigm, accessibility of

It stands for Object Oriented Programming. Object‐Oriented Programming ﴾223﴿ uses a different set of programming languages than old procedural programming languages ﴾& 3DVFDO, etc.﴿. Everything in 223 is grouped as self sustainable "REMHFWV". Hence, you gain reusability by means of four main object‐oriented programming concepts.

Object Oriented Programming 7 Purpose of the CoursePurpose of the Course To introduce several programming paradigms including Object-Oriented Programming, Generic Programming, Design Patterns To show how to use these programming schemes with the C programming language to build “good” programs.

Object Class: Independent Protection Layer Object: Safety Instrumented Function SIF-101 Compressor S/D Object: SIF-129 Tower feed S/D Event Data Diagnostics Bypasses Failures Incidences Activations Object Oriented - Functional Safety Object: PSV-134 Tower Object: LT-101 Object Class: Device Object: XS-145 Object: XV-137 Object: PSV-134 Object .

1. From structured programming to object-oriented programming 1 2. Towards Object-oriented Programming 7 3. Phenomena and Concepts 13 4. Towards Object-oriented Programs 19 5. The C# Language and System 23 6. C# in relation to C 25 7. C# in relation to Java 53 8. C# in relation to Visual Basic 57 9. C# Tools and IDEs 59 10.

Abstract—OOP (Object Oriented Programming) is an object-oriented programming method. The purpose of OOP is to facilitate the development of the program by following the models that have existed in everyday life. Object-oriented programming techniques are becoming very popular today in the process of creating multi-operating system applications.