StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Object Oriented Programing Languages - Report Example

Cite this document
Summary
This report "Object Oriented Programing Languages" discusses object-oriented programming languages that are dominant in terms of programming languages. The advantages that are offered make the languages more efficient and effective in computing processes as compared to structured programming…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER93% of users find it useful

Extract of sample "Object Oriented Programing Languages"

Object Oriented Programming in C# Student Name Course Institution Instructor Date of submission Introduction From time in memorial, human beings have sort to make work easier and faster in every way they deem possible. As such, technological advancement has been coupled with inventions to come up with strategies to automate repetitive tasks not only for speed in execution but also for standardization of results and quality enhancement. Within the course of the last century, computing devices have continued to evolve and so have the programs that are run in such devices. The languages that are used in the process of development of the devices and their functionalities have also evolved to be more efficient and elaborate (Harbour, 2005). Shaun Bebbington (2014) defines computer programming as the process through which executable programs are formulated to solve computing problems. The process is complex and can be tedious. It involves activities such as detailed analysis and understanding of the problem, verification of the algorithmic requirements, coding in a specific programming language, testing, debugging and finally maintenance of the developed program through routine checks for vulnerabilities and efficiency of the system (Maurer, 2006). At the start of the computing age, structured programming was used (Watt, 2004). This form of programming was done using programming languages such as Pascal and ALGOL used the top down design approach the scripting of the program thus reducing the need for go to statements. The system which was effectively divided into a number of compositional subsystems was not very effective thus creating the need to formulate object oriented programing languages such as C++, C#, PHP, Python, Java, Perl, Ruby etcetera (Budd, 2008). The evolved languages put more emphasis on objects that which possess attributes describing them (data fields) and methods (the associated procedures) that results to reusable and modular software systems. As a result, object oriented programming has led to programs that are easier to understand, easier to maintain and most importantly, adaptable to evolution (Clark, 2013). Although there might be a slight variation in the structure and functionality of the different object oriented programming languages, the basic structure / the skeleton of the code has a lot of similarity in terms of aspect such as classes, objects, encapsulation, inheritance, polymorphism, and inheritance (Reynolds-Haertle, 2002). Focus on the object in the program lead the developer to worry about the relationship between the various objects in the system rather than the implementation of the behavior of a specific object. This paper will look at the aspects of object oriented programming based on an automobile case study. These elements of object oriented programming will be sufficiently analyzed using C# as an object oriented programming language. Case Study When one takes a look at the ordinary automobile that you drive, it will be noted that the vehicle has properties like wheel size, engine size, gas tank size, and other properties which differentiate it from other automobiles. The automobile you drive is a concrete implementation of the automobile interface. Further analysis of the automobile will indicate that it has additional features, like sliding doors, logo type, cd changer slot count, moon roof lever location, or other various properties that are specific to the make/model of the car. In addition, automobile may have certain behaviors like open/close door, open trunk, turn wheel, and other behaviors that would be specific to an automobile and these features may or may not be available in other automobiles. The structure of object oriented programming can be illustrated using the automobile example. The automobile would be the base class, and each automobile manufacturer would have its own implementation based on their choices and preferences that would enhance efficiency of the vehicle. For instance, Honda has V-Tec technology, which is in its own implementation. Volvo uses diesel engines, which is the TDI technology. More importantly, you may add an added level of detail between automobile and the make/model implementation, such as Car, Truck, or Suv super types, to provide more relevant information. When it comes to C# and other object oriented programming languages, a class refers to an extensible program code template which has three primary functions. The first function is to create objects, the second function is to provide initial values (or member variables) for state and the other core function of classes is to implement behavior or enable member functions /methods (Jack, 2008). In most object oriented programming languages, the classes are named as class and is attached to several subroutine. When a constructor class is used to create an object, the product object is referred to as an instance. Consequently, the resulting variables are labeled instance variables so that there is a clear distinction between the said variable and the class variables which are a common denominator across a class (Purdum, 2012). Class structure All classes entail properties, attributes, data members and field descriptions. During program run time, it is these field names and types that are associated with state variables. In some programing languages, definition of the class is supported through specification of variants. Class behavior Methods are the key definitive components for classes or their instances. Purdum (2012) defines methods as subroutines which have the unique ability to make object and classes operationable. Essentially, the behavior can be through alteration of the opearation of the object or availing a means thruogh which an object can be access and utilized by a system. The types of methods vary depending on the type of objecty oriented programming language that is being used. In C#, the method is a series of statemenst that are contained in a code block. They include signatures which are declared in a class or struct through the specification of the access level and may or may not contain modifiers such as return value, abstract or sealed, method parameters and name of the method (Farrell, 2009). Class interface Interface of a class is realized upon the provision of structure and behavior. As illustrated above, whereas behavior is composed of code that dictates the implementation of methods, structure comprises of state and data. The interface is called and implemented at this level and the classes are made more effective (Dan, 2011). Member accessibility Object oriented programing languages facilitate restrictions to the access of methods by the classes in the program to facilitate efficiency in the utilization of resources. As such, there are three main ways through which member accessibility is accessed. The first access specifier is private. In this form of accessibility, there is restriction even to the class itself. Consequently, private member can only be access by methods that belong to that specific class. Methods that are part of other class rather than the particular class are not permitted to access the members. The second specifier is the protected access. In this case, the member is accesses by the class itself and subsequent sub classes (Mitchel, 2002). However the access is not universal and only the class and its subclasses can access the data. The third access specifier is the public access. This simply means that the member is accessible by any code in the system without any limitations. All though all the object oriented programming languages support all the above three specifiers, the semantics vary depending on the needs of the specific language. It is also worth noting that access specifiers do not necessarily control the visibility of the class or member. A member may be visible yet inaccessible based on the restrictions that have been set to manage the system. Inter class relationships The ability to relate classes without distorting the functionality of a program is considered to be one of the major advantages of object oriented programming languages. The design of the inter-class relationships can either be hierarchical or compositional. Hierarchical interclass relationships In the hierarchical interclass relationships, new classes are derived from existing classes. There is therefore a distinct relationship between the parent class / base class/ super class and the sub class / the child class (Mitchel, 2002). The former takes the higher levels in the hierarchy while the later takes the lower levels. As a result, the sub class or the child classes inherit the methods that are used by the super classes / the parent classes. The type of inheritance can either be single in heritance or multiple inheritance depending with the object oriented programming language that is being used. In that, single inheritance entails the subclass taking methods form the super class only whilemultiple inheritance means that the sub class can inherit methods form as many super classes as possible. Compositional Interclass relationships Composition relationships mean that a class is composed of other classes. This relationship is commonly refer to as the has-a relationship between enclosed classes and the embedded classes (Clark, 2013). In order to fully understand classes in object oriented programming languages, let's take a look at the automobile scenario with a bias to C#. Here is an example automobile class: public abstract class Automobile { //Properties public int DoorCount { .. } public string EngineType { .. } public float Height { .. } public float GasTankSize { .. } public float WheelBase { .. } public float WheelSize { .. }   //Abstract Properties public abstract string BodyType { get; }   //Methods public float CalculateFuelEfficiency(int lastMileage); } public abstract class Car : Automobile { //Properties public bool HasSpoiler { .. } public bool IsHatchback { .. }   //Overridden Properties (abstract) public override string BodyType { get { return "Car"; } }   //Abstract properties public abstract bool IsFast { get; } }   public abstract class Suv : Automobile { public bool CanOffroad { .. } public int TowingCapacity { .. }   public override string BodyType { get { return "SUV"; } } (In the above code) Notice the BodyType method is overridden to return a string that represents the type of body that's appropriate to the supertype. Also notice that Car and Suv also expose their own properties/methods, even abstractly in terms of the Car.IsFast property. Lastly, let's create an implementation of the Car class: public class SubaruWrx : Car { public override bool IsFast { get { return true; } } } The SubaruWrx class can use any of the properties defined in Automobile and Car classes. It has DoorCount, EngineType, etc. properties that are available, because it inherits from Car, which Car inherits from Automobile. You can cast SubaruWrx to Car or to Automobile, because it inherits from these base classes, and adds its own properties/methods. However, say you cast SubaruWrx to Automobile; none of the properties/methods defined in SubaruWrx or Car will be available, because all this object knows is that it's of type Automobile. To gain access to those properties/methods, you must up cast to the appropriate type. There are several ways that polymorphism can take place (Kendal, 2011). The first is through class inheritance, which you see above. Class inheritance exposes the interface of the base class to all of the derived classes. Another option is interface inheritance. The interface declares a contract that the class must follow to implement the interface. In addition to class inheritance, an object can inherit from one or more interfaces, which adds properties/methods to the body of the class that it must provide implementation for. This is another common option that can be used in .NET development. Some languages offer the ability to inherit from multiple base classes; however, .NET is not one of those languages. Encapsulation Encapsulation is one of the main pillars of object oriented programming that is supported using classes. It entails putting functions and data into a singular component. This process is used to protect data through selective hiding of the properties of the element. This form of protection is for two main purposes. First is to protect the data or elements from intentional manipulation and corruption by malicious people. The second function is to protect the function from accidental damage by users who were not malicious and did not intend to corrupt the system (Kendal, 2011). Most people think of encapsulation as a black box; data is sent to a method, a lot of work goes on using the data, of which you don't know or care about. An output is returned to the caller. That is the process of encapsulation, or information hiding. Let's take a look at the following class: public class MultiLineString { private CollectionBase _lines = null; private bool _allowEmptyLines = false; private static object _lock = new object();  public bool AllowEmptyLines { get { return _allowEmptyLines; } set { _allowEmptyLines = value; } }  public int LineCount { get { return _lines.Count; } }  public string this[int index] { get { return _lines[index]; } } public MultiLineString(string text) : this(text, false) { } public MultiLineString(string text, bool allowEmptyLines) { _allowEmptyLines = allowEmptyLines; _lines = new CollectionBase();  if (!allowEmptyLines) { string[] lines = text.Split('\n');   foreach (string line in lines) { if (line != null) this.Add(line); else if (line == '\r' && this.AllowEmptyLines) this.Add(string.Empty); } } } public MultiLineString(StringBuilder builder) : this(builder, false) { }  public MultiLineString( StringBuilder builder, bool allowEmptyLines) : this(builder.ToString(), allowEmptyLines) { }   public void AddLine(string line) { if (!this.AllowEmptyLines && string.IsNullOrEmpty(line)) throw new ArgumentNullException("line"); lock (_lock) { _lines.Add(this.TrimLine(line)); } }  public void RemoveLine(int index) { lock (_lock) { _lines.RemoveAt(index); } } public override string ToString() { string output = string.Empty;  foreach (string line in lines) output += line + "\n";  return output; } private string TrimLine(string line) { return line.Trim(new char[] { ' ', '\t', '\r' }); } } In the above code, each object is responsible to initialize and destroy itself. Therefore, there is no need to explicitly call a creation or termination procedure. This is one of the most efficient ways to encapsulate data. Another example of encapsulation in C# is as follows: class Program { publicclass Car{ privatedecimal carMileage= 30,000miles; publicdecimal CheckMileage (){ returnCarMileage; } } staticvoid Main(){ Account myCar=new Account(); decimal myMileage= myCar.CheckMileage(); } } Inheritance Inheritance is one of the prominent features that make object oriented programming stand out from structured programming. It takes place when a class or an object in a program is based on another class or object. This is when the objects or classes use the same implementation mechanism or when the implementation leads to the same behavior. Inheritance plays a crucial part in facilitating the reuse of code via the extensions of the original software’s interfaces and public classes thus reducing redundancy. It is of importance for any developer and learner to understand the difference between subtyping and inheritance. The composition of the element is key in efficiency when object oriented programming languages are concerned. There are two forms of inheritance that are used across all object oriented programming languages these are single inheritance and multiple inheritance (Farrell, 2009). Single inheritance is a case where a class or object is programmed to inherit from only one other object or class. The resulting hierarchical structure is the tree form which is easy to understand and implement due to the direct relationship of the objects and classes that are involved. The multiple inheritance system on the other hand is a situation where a class or object can inherit form more than one object/ class. This structure is more effective but it is also complex due to the integration of more than one element. The resulting hierarchical structure takes the lattice shape. Other forms of inheritance used by object oriented programming languages are prototype based inherence and differential inheritance. In these two cases, the inheritance is conducted directly between the objects (Purdum, 2012). There is also another form of inheritance that takes place in object oriented programming called uninheritable classes or objects. In such cases, the developer does not allow the inheritance of the features of the object or class (Mitchel, 2002). This is done through adding a modifier to the class declaration that renders the class uninheritable. The modifier will vary depending on the object oriented programming language used. For instance in C#, the modifier is the term sealed while in java, the modifier is the term final. One of the most common places where uninheritable classes are used is in projects where the developers do not have access to the source code but the pre compiled binaries only (Mitchel, 2002). In order for the uninheritable classes to be noticed faster at compile time, the classes in question do not possess any subclasses whatsoever. The aspect of protection is given a lot of attention and preference in object oriented programing languages. The concept of a private method is therefore introduced in the languages. In this concept, the sealed classescontain customized declarations whose method modifiers stop the method from being replaced by another function that carry’s the same signature or the identifying name (Mitchel, 2002). The no override feature is implemented through the exclusion of the class access to the objects. The functions of inheritance can be summarized as follows: It is used to expresses commonality among objects It allows code reusability in the program or system It highlights generalization and or specialization relationships in a program Polymorphism This term refers to the use of a single interface to a variety of entities which do not resemble each other (Booch, 2007). The types of polymorphism vary but the essential principle is that the application of one type is actually implementable in other types. In object oriented programming, there are three main categories of polymorphism. They include ad hoc polymorphism, subtyping and parametric polymorphism. Ad hoc polymorphismis the most popular of the three. It occurs when a function denotes not only heterogeneous but also independent implementations that are based on a limited variety of specified types and combinations. This is illustrated as follows. program Adhoc; function Add( x, y :Integer):Integer; begin Add := x + y end; function Add( s, t :String):String; begin Add := Concat( s, t ) end; begin Writeln(Add(1,2)); Writeln(Add('Hello, ','World!')); end. Subtyping (also known as inclusion polymorphism) occurs when a single name for a class, object or sub class is used to denote more than element as long as there is any form of class relationship. This is illustrated as follows using cars: abstractclass Car{ abstractString talk(); } class SubaruextendsCar{ String talk(){ return"V8 engine!"; } } class BMWextends Car{ String talk(){ return"V12 engine!"; } } void letsHear(Car a){ println(a.talk()); } void main(){ letsHear(new Subaru()); letsHear(new BMW()); } On the other hand parametric polymorphism (also known as generic programming) when a type is not specified in the entire code of a program (Jack, 2008). As a result, the type can be used universally with any number of typoes for as many times as possible as long as logic and the algorithmic function of the program is maintained. The concept of parametric polymorphism can be noted as below: data List a = Nil | Cons a (List a) length:: List a ->Integer length Nil =0 length(Cons x xs)=1+length xs map::(a -> b)-> List a -> List b map f Nil = Nil map f (Cons x xs)= Cons (f x)(map f xs) class List{ class Node{ T elem; Node next; } Node head; int length(){...} } List map(Func f, List xs){ ... } Exception Handling When writing code that may be affected by an exception in object oriented programming, a developer implements a try block which partitions the code to mitigate the effect (Reynolds-Haertle, 2002). The resulting exceptions are then handled through the use of associated catch blocks. The other option is the use of a finally block. The finally block will be run and implemented whether or not an exception collides with the try block that had been set up initially. Consequently, the resources that were allocated to the try block are released. In this case, a finally, block, a catch block or both will be required for the try block to be fully functional. System.IO.FileStream file = null; System.IO.FileInfo fileinfo = new System.IO.FileInfo("C:\\file.txt"); try { file = fileinfo.OpenWrite(); file.WriteByte(0xF); } finally { // Check for null because OpenWrite might have failed.  if (file != null) { file.Close(); } } Class constructors Whenever a new objects of a class are constructed, there is always a special member of the class that is constructed (Budd, 2008). The special member is referred to as a class constructor. In object oriented programming, the class and the constructor will share exactly the same name but will have no return type. This can be illustrated as follows: usingSystem; namespaceLineApplication { classLine { privatedouble length;// Length of a line publicLine() { Console.WriteLine("Object is being created"); } publicvoid setLength(double len ) { length = len; } publicdouble getLength() { return length; } staticvoidMain(string[] args) { Line line =newLine(); // set line length line.setLength(6.0); Console.WriteLine("Length of line : {0}", line.getLength()); Console.ReadKey(); } } } The result of the compilation and execution of the program code above results to: Object is being created Length of line : 6 Destructors Whenever an object in a said class gets out of scope, a special member function from the same class is put to execution (Clark, 2013). This special member function is the destructor and it will share the name of the class. Howver, it will be prefixed with ~ so that there is a variation. The destructors are primarily used to release the resources that were being used before a program is closed for instance the memory of a computing device. The destructor concept used in object oriented programming is illustrated in the C# code for the program below. usingSystem; namespaceLineApplication { classLine { privatedouble length;// Length of a line publicLine()// constructor { Console.WriteLine("Object is being created"); } ~Line()//destructor { Console.WriteLine("Object is being deleted"); } publicvoid setLength(double len ) { length = len; } publicdouble getLength() { return length; } staticvoidMain(string[] args) { Line line =newLine(); // set line length line.setLength(6.0); Console.WriteLine("Length of line : {0}", line.getLength()); } } } The result of the compilation and execution of the program code above results to: Object is being created Length of line : 6 Object is being deleted Static Class Members When a member of a class is regarded as static, it implies that there will be only one copy of the member (static), no matter how many objects of the class are created. Because the values of static functions can be retrieved through simple invocation of classes without the need to create an instance, they are utilized for constants definitions (Maurer, 2005). The functionality of static members in object oriented programming is illustrated in the C# code below. usingSystem; namespaceStaticVarApplication { classStaticVar { publicstaticint num; publicvoid count() { num++; } publicint getNum() { return num; } } classStaticTester { staticvoidMain(string[] args) { StaticVar s1 =newStaticVar(); StaticVar s2 =newStaticVar(); s1.count(); s1.count(); s1.count(); s2.count(); s2.count(); s2.count(); Console.WriteLine("Variable num for s1: {0}", s1.getNum()); Console.WriteLine("Variable num for s2: {0}", s2.getNum()); Console.ReadKey(); } } } The results after compiling and executing the code is: Variable num for s1: 6 Variable num for s2: 6 Conclusion Object oriented programing languages are the dominant in terms of programing languages. The advantages that are offered make the languages more efficient and effective in computing processes as compared to structured programming. The clear understanding of the principles and guidelines of specific object oriented programming languages is of fundamental importance to any developer or student in the world of computing. References Budd, T. (2008). Introduction to Object-Oriented Programming. New Jersey: Pearson Education. Chandra, B.. Object oriented programming using C++. 2nd ed. Harrow, U.K.: Alpha Science International, 2005. Print. Clark, D. (2013). Beginning C# Object-Oriented Programming. New York: Apress. Dan, C. (2011). Beginning C# Object-Oriented Programming. New York : Apress. David Anthony Watt; William Findlay (2004). Programming language design concepts. John Wiley & Sons. pp. 215–221. Deitel, Harvey M., and Paul J. Deitel. C++: how to program. 3rd ed. Upper Saddle River, NJ: Prentice Hall, 2001. Print. Farrell, J. (2009). Microsoft Visual C# 2008 Comprehensive: An Introduction to Object-Oriented Programming. Boston : Cengage Learning. Grady Booch (2007), Object-Oriented Analysis and Design with Applications. Addison-Wesley Harbour, Jonathan S. (2005). Beginning game programming. Boston, Mass.: Thomson/Course Technology PTR. Print. Jack, P. (2008). Beginning C# 3.0: An Introduction to Object Oriented Programming. New York: John Wiley & Sons. Kendal, S. (2011). Object Oriented Programming using C#. London : Bookboon. Maurer, Ward Douglas (2006)"A theory of computer instructions." Science of Computer Programming 60.3: 244-273. Print. Mitchel John(2002). "10 "Concepts in object-oriented languages"". Concepts in programming language. Cambridge, UK: Cambridge University Press. p. 287. Purdum, J. (2012). Beginning Object-Oriented Programming with C#. New York: John Wiley & Sons. Reynolds-Haertle, R. A. (2002). OOP with Microsoft Visual Basic.NET and Microsoft Visual C# .NET step by step. Carlifornia : Microsoft Press. Pressman, Roger S., and David Brian Lowe. Web engineering: a practitioner's approach. Boston: McGraw-Hill Higher Education, 2009. Print Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(Object Oriented Programing Languages Report Example | Topics and Well Written Essays - 3750 words, n.d.)
Object Oriented Programing Languages Report Example | Topics and Well Written Essays - 3750 words. https://studentshare.org/logic-programming/2052276-c-language
(Object Oriented Programing Languages Report Example | Topics and Well Written Essays - 3750 Words)
Object Oriented Programing Languages Report Example | Topics and Well Written Essays - 3750 Words. https://studentshare.org/logic-programming/2052276-c-language.
“Object Oriented Programing Languages Report Example | Topics and Well Written Essays - 3750 Words”. https://studentshare.org/logic-programming/2052276-c-language.
  • Cited: 0 times

CHECK THESE SAMPLES OF Object Oriented Programing Languages

Object Oriented Programming

There are two paradigms that are followed to write computer programs: ‘procedural' or of the of the of the object oriented Programming INTRODUCTION A Computer Program is a series of instructions that tells a computer what tasks it needs to perform and in what sequence.... There are two paradigms that are followed to write computer programs: ‘procedural' or ‘object oriented.... As compared to this, in an object oriented approach, related data and functions are grouped together in order to create objects....
1 Pages (250 words) Research Paper

Application Development and Programming Languages

object oriented programming language, like java, provides an easy programmability procedure.... Application Development and Programming Languages object oriented language and imperative language differ from one inmany way as follows; Programmability of programming language refers to the ability of that language to modify itself as per the programmer's requirements.... object oriented programming language, like java, provides an easy programmability procedure....
2 Pages (500 words) Essay

Manipulating Data and Structured Programming

The programming languages are determined by the programming paradigms that they support.... The programming languages are determined by the programming paradigms that they support.... Some of the programming languages use multiple paradigms and the programmers have to decide whether how to use these paradigms.... Concepts in Programming languages.... In the past 60 years, there have been many different ways through… which programming has evolved in collective grouping and manipulating data by spaghetti code, structured programming, modular programming, and object-oriented programming. Spaghetti code is a particular programming code which was initially used in programming....
2 Pages (500 words) Essay

Object-oriented vs traditional structured

Structured verses object oriented programs Structured verses object oriented programming Introduction A program relates to a set ofinstructions that shows how to solve a predefined problem or task.... It is indispensable to note that object oriented programming remains as the most high-level, flexible, and reusable program compared to structured programming.... object oriented programming (OPP), is much advanced than the structured programming languages since it incorporates three important principles of software development like encapsulation for data hiding which is not common in structured system....
2 Pages (500 words) Essay

Proof, Language, and Interaction: Essays in Honour of Robin Milner

Henderson 2009, asserts that Ole-Johan Dahl and Kristen Nyagarard are pioneers in computing and are widely acknowledged for the ideas in object oriented programming through their development of the programming languages Simula 1 and Simula 67.... Simula refers to simulation programming languages mentioned above developed by the two pioneers mentioned above, and from computing analysts it is a good superset of ALGOL 60.... Simula is thought of one of the original object focuses programming language and it was designed to be used for performing simulations and the need for the domain given the framework for a variety of the features of the object focused languages that are in existence currently....
2 Pages (500 words) Assignment

Classes and Methods in Python

Object-oriented programming on the other hand is a style of programming where data and operations that operate it are arranged into classes and… (http://thinkpython.... It involves changing the behavior of an operator like + so it works with a Chapter 17 es and methods Object-oriented features Object-oriented language is a language that uses method syntax and user-defined classes, to facilitate object-oriented programming....
2 Pages (500 words) Essay

Peculiarities of Computer Programming

He added object oriented features borrowed from Simula into C to create a new programming language that was fast, efficient and easier to design.... The idea of creating C++ arose from a need for features that were not possible with other languages at that time.... Bjarne Stroustrup had worked with Simula, the first object-oriented programming language.... Programming Generation - Third Generation Programming Paradigm(s) – Structured programming, Inheritance, Polymorphism, Free-form, Type-checking, statically typed, Data abstraction, Object-oriented (Downey, n....
2 Pages (500 words) Essay
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us