4 Object.docx

# 4 Object.docx

This preview shows pages 1–3. Sign up to view the full content.

4 Object-Oriented Concepts Peter Müller Globewide Network Academy (GNA) [email protected] The previous sections already introduce some ``object-oriented'' concepts. However, they were applied in an procedural environment or in a verbal manner. In this section we investigate these concepts in more detail and give them names as used in existing object-oriented programming languages. 4.1 Implementation of Abstract Data Types The last section introduces abstract data types (ADTs) as an abstract view to define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once an ADT is implemented we have a particular representation of it available. Consider again the ADT Integer . Programming languages such as Pascal, C, Modula-2 and others already offer an implementation for it. Sometimes it is called int or integer . Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: int i, j, k; /* Define three integers */ i = 1; /* Assign 1 to integer i */ j = 2; /* Assign 2 to integer j */ k = i + j; /* Assign the sum of i and j to k */ Let's play with the above code fragment and outline the relationship to the ADT Integer . The first line defines three instances i , j and k of type Integer . Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ``binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ``constructed'' by the definition of i . Optionally, compilers might choose to initialize the memory, for example, they might set it to 0 (zero). The next line i = 1; sets the value of i to be 1. Therefore we can describe this line with help of the ADT notation as follows:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Perform operation set with argument 1 on the Integer instance i. This is written as follows: i.set(1). We now have a representation at two levels. The first level is the ADT level where we express everything that is done to an instance of this ADT by the invocation of defined operations. At this level, pre- and postconditions are used to describe what actually happens. In the following example, these conditions are enclosed in curly brackets. { Precondition: i = n where n is any Integer } i.set(1) { Postcondition: i = 1 } Don't forget that we currently talk about the ADT level! Consequently, the conditions are mathematical conditions. The second level is the implementation level, where an actual representation is chosen for the operation. In C the equal sign ``='' implements the set() operation. However, in Pascal the following representation was chosen: i := 1; In either case, the ADT operation set is implemented.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern