Oct 09 Di Poop Report

Embed Size (px)

Citation preview

  • 8/10/2019 Oct 09 Di Poop Report

    1/10

    THE BCS PROFESSIONAL EXAMINATIONBCS Level 5 Diploma in IT

    October 2009

    EXAMINERS' REPORT

    Object Oriented Programming

    Section A

    Answer Section A questions in Answer Book A

    Question A1

    a) Compare and contrast:

    i) Structured programming ;ii) Programming using abstract data types ;iii) Object oriented programming.

    (15 marks)

    Answer pointers

    Structured programming: A technique for organizing and coding computer programs in which a hierarchyof modules is used, each having a single entry and a single exit point, and in which control is passeddownward through the structure without unconditional branches to higher levels of the structure. Threetypes of control flow are used: sequential, test, and iteration.

    A collection of data and a set of operations on that data is called an Abstract Data Type. The definition ofthe operations must be rigorous enough to specify completely the effect that they have on the data yet thedefinition must not specify how to store the data nor how to carry out the operations. This leads to datahiding and encapsulation.

    O-O programming languages take the concept of an abstract data type and makes it possible to use ADTs as first class types in the language (i.e. variables can have a user-defined type). In addition OOlanguages allow new types to be developed through an inheritance mechanism.In structured programming control flow is the most important issue, whereas with ADTs and OOprogramming data and its associated operations are the most important issue. OO approaches improveon ADT programming by treating ADTs as types in their own right and by supplying a mechanism to re-use existing code.

    (b) Describe five advantages of the object oriented programming paradigm.

    (10 marks)

    Answer Poin ters

    Candidates might have discussed any of the following issues (or any others that are appropriate):

    Faster development

  • 8/10/2019 Oct 09 Di Poop Report

    2/10

    Increased QualityEasier maintenanceEnhanced modifiabilityExploit power of OOP languagesReuse of software and designs, frameworksSystems more change resilient, evolvableReduced development risks for complex systems, integration spread out

    Appeals to human cognition, naturalness

    Examiners CommentsThis question examines part 8A of the syllabus: Foundations

    The majority of candidates chose to answer this question, however, only a few obtained high marks. Ingeneral, candidates obtained a bare pass by answering part a) of the question but scored poorly on partb). There continues to be a confusion between Abstract Data Types and Abstract Classes and Methods.

    The answers to part b) were disappointing in that candidates seem to be unable to justify the use ofobject oriented programming techniques. The majority of answers simply listed features of object orientedprogramming without stating what advantages they offered the programmer.

    Question A2

    a) Explain the following:

    i) abstract method ;ii) abstract class ;iii) abstraction .

    (9 marks)

    Answer Poin ters

    i) An abstract method is effectively a placeholder in a superclass. It defines a method that will

    appear in one or more subclass definitions but does not provide code to implement the method.

    ii) An abstract class may be declared explicitly as abstract or it maybe implicitly abstract because itcontains an abstract method. It is a class which cannot be instantiated.

    iii) Abstraction is the process of generalising by reducing the amount of information in a givensituation to that relevant for fulfilling a particular purpose.

    b) How do abstract methods and abstract classes support polymorphism ? Illustrate youranswer with at least one code example.

    (8 marks)

    Answer Poin ters

    An abstract superclass effectively defines all the methods that its subclasses must implement withoutstating the details of that implementation. This means that the subclasses can have different ways ofimplementing a method with the same name. For example, there might be a superclass called Shape. Itmay make little sense to be able to instantiate Shape since we need to be more specific about the exactshape e.g. circle or rectangle. We might, however, know that all Shapes can be drawn so we can includedraw() as an abstract method of Shape. Each subclass of Shape will implement its own version of draw().

    Suppose Circle and Rectangle are subclasses of Shape. Consider the code:

  • 8/10/2019 Oct 09 Di Poop Report

    3/10

    Shape c = new Ci r cl e( ) ;Shape r = new Rect angl e( ) ;

    Thenc. dr aw( ) ;r . draw( ) ;

    will invoke different versions of draw.

    c) Explain how polymorphism supports code reuse.(8 marks)

    Answer Poin ters

    If we have a language which supports polymorphism via inheritance, then we only have to rewrite thoseparts of the behaviour which are different. For example, if the only difference between Rectangle and

    Circle is that they are drawn differently, then we can put all the common code into Shape and simplyimplement draw() in both classes. Code which is common to both classes is only written once and onlymethods which express behaviour which varies need to be written separately. In this way the majority ofcode is reused.

    Examiners CommentsThis question examines part 8B of the syllabus : Concepts

    Again this was a popular question in which candidates gained bare passes by answering the earlier parts.The later parts of the question were less well answered. Answers to part a) generally provided correctdefinitions of abstract method and abstract class but many candidates were unable to define abstraction.Pat b) was less well answered and only a few candidates were able to provide convincing codeexamples. In part c) candidates were able to define polymorphism and code reuse but seemed unable toconnect the two ideas.

    Question A3

    a) Explain the following terms:

    i) object ;ii) class .

    (6 marks)

    Answ er Po in ter s

    An object combines data elements with operations on those elements. In many cases the datamay only be manipulated via the associated operations.

    A class is used to define the data elements and operations that an object possesses. Object arecreated by instantiating a class.

    b) Using code examples describe the following three types of inter-class relationship:

    i) inheritance ;

  • 8/10/2019 Oct 09 Di Poop Report

    4/10

    ii) association;iii) aggregation .

    (9 marks)

    Answer Poin ters

    Inheritance is a way to form new classes using classes that have already been defined. The new classes,known as derived classes, take on (or inherit) attributes and behaviour of the pre-existing classes, whichare referred to as base classes or super classes. It is intended to help reuse existing code with little or nomodification.

    cl ass mySuper Cl ass{}

    cl ass mySubCl ass ext ends mySuper Cl ass{}

    Association defines a relationship between classes of objects which allows an object instance to causeanother to perform an action on its behalf. This relationship is structural, because it specifies that objects

    of one kind are connected to objects of another.cl ass Cl ass1{

    Cl ass2 c;}

    cl ass Cl ass2{Cl ass1 c;

    }

    Aggregation is a special type of association typified by the situation where an object consists of a numberof sub-parts. Sub-parts have an existence independent of the main part but may only be sub-parts of asingle part.

    cl ass Cl ass2{}

    cl ass Cl ass1{Cl ass2[ ] c ;

    }

    c) Use a code example to describe what is meant by delegation and explain the benefits of thistechnique.

    (10 marks)

    Answer Poin ters

    Delegation is the concept of handing a task over to another object. In object-oriented programming it isused to describe the situation where one object defers a task to another object, known as the delegate.

    class Delegate {void method1() { System.out.println("Delegate doing method1()"); }void method2() { System.out.println("Delegate doing method2()"); }

    }

    class MyClass {

  • 8/10/2019 Oct 09 Di Poop Report

    5/10

    // delegationDelegate delegate = new Delegate();

    void method1() { delegate.method1(); }voi d met hod2( ) { del egat e. met hod2( ) ; }

    }

    publ i c cl ass Mai n {publ i c st at i c voi d mai n( St r i ng[ ] ar gs) {

    MyCl ass x = new MyCl ass( ) ;x. met hod1( ) ;x. met hod2( ) ;

    }

    This approach comes in useful where MyClass is supplied as a class which may not be altered but wewish to tailor its behaviour for a particular situation. Class Delegate can be written to accommodate theparticular concerns of the context and the overall behaviour of the program will modify accordingly.

    Examiners Comments

    This question examines part 8B of the syllabus : Concepts

    This question was only attempted by a third of the candidates. The average mark was quite low becausevery few of the candidates supplied adequate solutions to parts b) and c) of the question. A number ofcandidates chose to answer part b) by producing UML diagrams which represent inheritance, associationand aggregation. The question clearly asked for code examples and consequently these answers werenot given any credit. It was clear from the answers given to part c) that most candidates did notunderstand the term delegation in the context of object oriented programming.

    Section B Answer Section B questions in Answer Book B

    Question B4

    a) In the context of a design pattern, explain what is meant by the following: motivation,prerequisites, structure, participants and consequences.

    (10 marks)

    Answer Poin ters

    When defining a design pattern, the following should be covered as part of the documentation:

    Motivation scenario consisting of a problem and a context in which this pattern can be used.

    Prerequisites what needs to be in place beforehand.

    Structure graphical representation of the pattern. Class diagrams and Interaction diagrams may

    be used for this purpose.Participants listing of the classes and objects used in the pattern and their roles in the design.

    Consequences description of the results, side effects, and trade offs caused by using thepattern.

    b) Give an example of three different types of design patterns, explaining what type of problems theyaim to resolve, include an example of their use.

    (15 marks)

  • 8/10/2019 Oct 09 Di Poop Report

    6/10

    Answer Poin ters

    Three design patterns are required, which could include the following. A short description is required foreach one, which should include a simple example and an explanation of when it should be used.

    Adapter

    The Adapter is intended to provide a way for a client to use an object whose interface is different from theone expected by the client, without having to modify either. This pattern is suitable for solving issues suchas replacing one class with another when the interfaces do not match and creating a class that caninteract with other classes without knowing their interfaces at design time.

    DecoratorOrdinarily, an object inherits behaviour from its subclasses. The decorator pattern allows the behaviour ofan object to be extended and dynamically compose an object's behaviour. Decorator allows this withoutthe need to create new subclasses.

    IteratorThe Iterator pattern provides a way to access the elements of an aggregate object sequentially withouthaving to know the underlying representation. Iterator also provides a way to define special Iterator

    classes that perform unique processing and return only specific elements of the data collection. TheIterator is useful because it provides a common interface so programmer does not need to know anythingabout the underling data structure.

    ObserverThe Observer pattern is useful when data is to be presented in several different forms at once. TheObserver is intended to provide a means to define a one-to-many dependency between objects so thatwhen one object changes state, all its dependents are notified and updated automatically. The objectcontaining the data is separated from the objects that display the data and the display objects observechanges in that data. Often used in MVC.

    SingletonThe singleton pattern applies to the many situations in which there needs to be a single instance of a

    class, a single object. Print spoolers and window managers are examples of Singletons. The Singleton isintended to provide a way to ensure that a class provides one instance of itself, and to provide a globalpoint of access.

    Abstrac t factoryProvides an interface for creating families of related or dependent objects without specifying theirconcrete classes

    Object PoolManages the reuse of objects for a type of object that is expensive to create or only a limited number of akind of object can be created.

    Examiners CommentsThis question examines parts 8c & 8d of the syllabus Design and Practice

    This question was attempted by a third of the candidates. For Part A. a lot of answers gave a generaldescription of what a design pattern was, but did not always describe them in the context of motivation,prerequisites, structure, participants and consequences, so lost marks. Higher marks were given toanswers that covered these areas.

    Part B was generally answered adequately, most candidates could give a general description of threedesign patterns, but did not always state what they aimed to resolve, or include any example of their use,which was needed to gain full marks.

  • 8/10/2019 Oct 09 Di Poop Report

    7/10

    Question B5

    The Very Large Programming Conference (VLPC) is an annual international conference that is held everySeptember in a different country. Each year a call for papers invites academics to write papers for theconference. Authors write their papers and submit them to the conference for reviewing. The conferencehas a Programme Chair who appoints the reviewers, who are called the Programme Committee. A subsetof this Committee are chosen to be Regional Chairs. After the closing date for submissions, the RegionalChairs assign each paper from their region a unique number and then send it out to two reviewers. Eachreviewer will review their allocated papers, by providing a score fore each paper and comments for theauthor(s).

    The Regional Chair will collate the reviewers comments and will produce a list of papers, ordered by theirscore, which will be sent to the Programme Chair. The Programme Chair makes the final decision on thepapers. Those with high scores will be accepted for the conference, whereas papers with a low score willbe rejected outright. Depending on the reviewers comments, a further decision will be made as towhether a paper needs to be revised by the authors; or can be accepted for the conference withoutchanges. If a paper needs revisions, the authors have to resubmit a new version within a monthsdeadline. When the required number of papers have been accepted for the conference, the ProgrammeChair will produce a Conference Programme.

    a) Draw a use case diagram for this system(15 marks)

    Answ er Po in ter s

  • 8/10/2019 Oct 09 Di Poop Report

    8/10

    b) Discuss how Use Case diagrams and descriptions provide an overview of the user requirementsof a system. Within your answer include examples from the above system.

    (10 marks) Answer Poin ters

    The candidate should discuss where Use Cases should be used in developing a system.

    As part of the development process, the designer should develop a set of scenarios for each Use Caseon the Use Case Diagram. Scenarios are natural language descriptions of an instantiation of the UseCase.

    These can be used in the following areas:

    - Initial investigation- For identifying what functionality is required from the system- The descriptions give the fuller detail- Testing purposes

    The candidate should include a brief example of a scenario to illustrate their points.

    Examiners CommentsThis question examines parts 8c of t he syllabus Design

    This proved to be a popular question and was generally answered well. Most candidates produced agood Use Case diagram for Part A, identifying the main Use Cases and Actors. Marks were lost if the Use

  • 8/10/2019 Oct 09 Di Poop Report

    9/10

    Case was not connected to the correct Actor, or had inappropriate ext end or i ncl ude relationships.Lower marks were given where the Use Cases were not correctly identified, or wordy descriptions of allthe actions were included.

    A number of candidates did not answer Part B correctly, giving lengthy Use Case descriptions, which mayhave been more appropriate to a previous exam paper. Some answers just described the diagram from

    Part A, so again gained little credit. To gain a high mark, the answer should discuss how Use Cases areused to develop a system.

    Question B6

    Given the following Class diagram:

    -commission : float

    Sales Person

    -staffNo : int-name : string-address : string-salary : float

    Staff

    #departmentNo : int#departmentName : string+noOfDepartments : int

    Department-worksFor

    1..*

    -employs

    1

    a) Using an object-oriented language that you are familiar with, write code to produce the following:

    a. Class definitions for all classes(10 marks)

    b. A constructor for Department, with 2 parameters for departmentNo anddepartmentName. noOfDepartments should be incremented each time a Department iscreated. Show how this constructor can be used in practice.

    (6 marks)

    Answer Poin ters

    Sample Java code:

    public class Department{protected int departmentNo;protected String departmentName;public static int noOfDepartments = 0;

    public Department (int deptno, String dname) {departmentNo = deptno;departmentName = dname;noOfDepartments ++;}

    }abstract class Staff{

    private int StaffNo;

  • 8/10/2019 Oct 09 Di Poop Report

    10/10

    private String name;private String address;private float salary;private Department worksFor;

    }class SalesPerson extends Staff {

    private float commission;}public class DeptTest {

    Department d1 = new Department(10,"Test");}

    b) Discuss how the above object-oriented code can be tested.

    (9 marks)

    Answer Poin ters

    An open-ended question. The candidate may look at different approaches, for example:

    - Fault based testing- Scenario based testing

    Or may discuss black-box and white-box testing with respect to OO programming.

    Examiners CommentsThis question examines parts 8d of th e syllabus Practice

    This proved to be a popular question and Part A was generally answered well. Most candidates couldprovide the basic class definitions and the constructor. Exact syntax was not required, though somecandidates gave very sketchy class definitions and did not include any data types. Other marks were lostby not defining the class variable, abstract class or the instantiation of the class. The candidates who

    obtained high marks demonstrated evidence of having practical experience of object-orientedprogramming, such as C++, Java or a .NET language.

    A lot of candidates described white and black box testing in Part B, but lost marks by not saying howthese could be used in the context of object-oriented programming. Some candidates lost marks bydescribing how to debug code, rather than test it.