Sample Research Paper on Object Oriented Programming

Object Oriented Programming

Object-oriented programming refers to a programming paradigm that employs abstraction, a given form of classes and objects, to form models found on the real world setting.  Apparently, an object-oriented application employs an anthology of objects that communicate by sending messages to request services.  In addition, objects are proficient in conveying messages, receiving them as well as processing the conveyed data.  Object-oriented programming aims at trying to boost the flexibility and maintainability of computer programs.  Pragmatically, programs developed by means of an OO language tend to be modular thus they are easier to develop and also simpler to comprehend after development (Yeager, 2014).

Object-Oriented Programming vs. Procedural Programming

Nearly all programs are fabricated using modules, which are elements of a program. They can be separately coded and tested and later assembled to make a complete functional program (Gifford, 2010).  However, in procedural languages, that is, C language, the modules comprise of procedures which are sequence of statements.  For instance in C, procedures refer to a sequence of imperative statements that include tests, assignments, loops as well as invocations of sub procedures.  Additionally, these procedures are also functions that map arguments that are aimed at returning statements.

The design technique employed in procedural programming is known as the Top Down Design.  Basically this implies that this is where you begin with an issue or a problem (procedure) and subsequently break down the problem into several sub problems (sub procedures) (Gifford, 2010).  This is commonly referred to as functional decomposition that aims at persisting until a sub problem is clearly-cut to be worked out using a corresponding sub procedure.  However, this type of programming has some difficulties that comprise of software maintenance which can tend to be difficult and also time consuming (Purao, H, & Nazareth, 2002).  Notably, whenever amendments are made to the core procedure (top), they can be distributed to the sub procedures of the core procedure together with the sub-sub procedures. It should be noted that the changes may crash all the procedures in the pyramid.

Object oriented programming is considered as an alternative to procedural programming. This is because of its preeminent technique in addressing difficulties experienced in procedural programming (Gifford, 2010). Basically, this is viable because object oriented programming uses classes in its modules as compared to procedures which are complicated. This approach of using classes in object-oriented programming enables people to create objects that mimic the real world.

An example of a class with at least one attribute

An attribute offers an influential technique of connecting declarative information using C# code that may include methods, types, properties etc. After the attribute has been associated with a given program entity, it can be queried at run time and as well utilized in several ways.

Applications of attributes includes:

  • Associating any help needed in documenting the program entities (by use of a Help attribute).
  • Associating certain value editors to a particular style in a GUI framework (by use of a Value Editor attribute).

A complete example indicating all pieces brought together by use of attributes.

// This example reveals the application of class and method attributes (Yeager, 2014).

 

using System;

using System.Reflection;

using System.Collections;

 

// The IsTested class is a user-defined custom attribute class.

// It can be applied to any declaration including

//  – types (struct, class, enum, delegate)

//  – members (methods, fields, events, properties, indexers)

// It is used with no arguments.

public class IsTestedAttribute : Attribute

{

public override string ToString()

{

return “Is Tested”;

}

}

 

// The AuthorAttribute class is a user-defined attribute class.

// It can be applied to classes and struct declarations only.

// It takes one unnamed string argument (the author’s name).

// It has one optional named argument Version, which is of type int.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]

public class AuthorAttribute : Attribute

{

// This constructor specifies the unnamed arguments to the attribute class.

public AuthorAttribute(string name)

{

this.name = name;

this.version = 0;

}

 

// This property is readonly (it has no set accessor)

// so it cannot be used as a named argument to this attribute.

public string Name

{

get

{

return name;

}

}

 

// This property is read-write (it has a set accessor)

// so it can be used as a named argument when using this

// class as an attribute class.

public int Version

{

get

{

return version;

}

set

{

version = value;

}

}

 

public override string ToString()

{

string value = “Author : ” + Name;

if (version != 0)

{

value += ” Version : ” + Version.ToString();

}

return value;

}

 

private string name;

private int version;

}

 

// Here you attach the AuthorAttribute user-defined custom attribute to

// the Account class. The unnamed string argument is passed to the

// AuthorAttribute class’s constructor when creating the attributes.

[Author(“Joe Programmer”)]

class Account

{

// Attach the IsTestedAttribute custom attribute to this method.

[IsTested]

public void AddOrder(Order orderToAdd)

{

orders.Add(orderToAdd);

}

 

private ArrayList orders = new ArrayList();

}

 

// Attach the AuthorAttribute and IsTestedAttribute custom attributes

// to this class.

// Note the use of the ‘Version’ named argument to the AuthorAttribute.

[Author(“Jane Programmer”, Version = 2), IsTested()]

class Order

{

// add stuff here …

}

 

class MainClass

{

private static bool IsMemberTested(MemberInfo member)

{

foreach (object attribute in member.GetCustomAttributes(true))

{

if (attribute is IsTestedAttribute)

{

return true;

}

}

return false;

}

 

private static void DumpAttributes(MemberInfo member)

{

Console.WriteLine(“Attributes for : ” + member.Name);

foreach (object attribute in member.GetCustomAttributes(true))

{

Console.WriteLine(attribute);

}

}

 

public static void Main()

{

// display attributes for Account class

DumpAttributes(typeof(Account));

 

// display list of tested members

foreach (MethodInfo method in (typeof(Account)).GetMethods())

{

if (IsMemberTested(method))

{

Console.WriteLine(“Member {0} is tested!”, method.Name);

}

else

{

Console.WriteLine(“Member {0} is NOT tested!”, method.Name);

}

}

Console.WriteLine();

 

// display attributes for Order class

DumpAttributes(typeof(Order));

 

// display attributes for methods on the Order class

foreach (MethodInfo method in (typeof(Order)).GetMethods())

{

if (IsMemberTested(method))

{

Console.WriteLine(“Member {0} is tested!”, method.Name);

}

else

{

Console.WriteLine(“Member {0} is NOT tested!”, method.Name);

}

}

Console.WriteLine();

 

 

The relationship between the class, attributes, and methods in the above code construct

Class – The class Is Tested is made up of other classes therefore it has a has-relationship which is also known as a compositional relationship. Basically, there exists a compositional relationship between the enclosing class in place and the embedded ones.

Attributes – This refers to the location in which objects store their data in. For instance, this.name and this.version are the attributes in the above code construct.

Methods – they are similar to function and are defined within a given class with an aim of making an explicit relationship. Examples include keys and values. Notably, every method is related to a given class and is aimed at invoking instances belonging to that class.

Describe at least one feature of object-oriented programming that Visual Logic lacks.

Visual Logic is mostly used as a commercial tool aimed at carrying out academic projects (Purao, H, & Nazareth, 2002). It is preeminent in supporting creation of programs by use of multiple procedures, whereby each procedure is signified as a flowchart. In addition, Visual language encloses a number of built-in functions that originate from Visual Basic. Basically, Visual Logic lacks the ability to create classes and does not support it either.

The advantage of using object-oriented programming is that it applies modules for the creation of classes thus they are easier to develop and also simpler to comprehend after development. It also mimics the real world applications unlike in procedural programming (Yeager, 2014).

 

 

Conclusion

Object-oriented programming is favorable for use because it gives space for rapid development, re-use of codes as well as designs and also easy to maintain. The object classes smoothens the progress of rapid development by means of lessening the semantic gap that tends to exist between users and the codes. They also bring about the ease of maintenance by use of encapsulation. In addition, the re-use of software is a key benefit in regards to the use of object class

References

Gifford, M. (2010). Object-oriented programming in ColdFusion: Break free from procedural

programming and learn how to optimize your applications and enhance your skills using

objects and design patterns. Birmingham [United Kingdom: Packt Pub.

Purao, S., Jain, H. K., & Nazareth, D. L. (May 01, 2002). Exploiting design information to derive

object distribution models. Ieee Transactions on Systems, Man, and Cybernetics – Part A: Systems and Humans, 32, 3, 320-334

Yeager, D. P. (2014). Object-oriented programming languages and e