Home > IB Computer Science 2014, IB Computer Science 2015 > More on how to score well in exams

More on how to score well in exams

January 24, 2014 Leave a comment Go to comments

Explain the advantages of encapsulation in software development (6 marks)

Important points when answering a question like this:

  • Look for the command term. What does “explain” mean? It means state with reasons.
  • Each point is likely to get 2 marks: one for stating, one for the reason.
  • Use words like “because” to structure your answer and show the examiner that you are (1) stating… (2) with reasons. Help the examiner give you marks!
  • Although the question doesn’t overtly ask for a definition, stick one down anyway; you won’t get penalised for it and you might pick up a mark that you would otherwise have missed.
  • It’s always a good idea to stick a bit of code down because
    • It tends to score a lot of marks
    • It’s easy
    • It gives you something to refer to in the rest of your answer

Here are some examples of good ways to score marks in a question like this. (There is far more information here than would be required for a six-mark question, but it’s always a good idea to put down a little more than is required if you have time.) I have included the points at which I think an examiner would give you a mark.

The idea of encapsulation is to restrict access to the implementation of an object by exposing a public interface (mark). This is also known as “data hiding”. (mark)

Example:

class Student {
  private String name;
  public String getName(){
    return name;
  }
  public void setName(String s){
    name = s;
  }
}

 (marks!)

The variable name is declared private and therefore cannot be accessed from outside the class (mark). The name is made accessible by the “accessor” methods getName() and setName() which are declared public and so can be accessed from anywhere (mark).

Advantages of encapsulation:

  • Makes data more secure (mark) because it prevents other objects from accessing an object’s private variables and methods (mark).
  • Makes objects easier for other programmers to use (mark) because complex and possibly confusing code is hidden (mark)
  • Increases software reliability (mark) because even if an object’s implementation is changed, its interface can remain the same and so other parts of the program that use the object do not need to be changed (mark).
  • Makes collaboration on projects easier (mark) because the interface of an object can be specified before it is coded thereby allowing other developers who plan to use the object to start work earlier (mark).

A car is a good real-world example of encapsulation because:

  • The confusing “implementation” of the car (ie how it works) is kept under the hood (mark).
  • A simple “interface” is provided, in the form of a steering wheel, gear stick and pedals (mark)

This allows users to focus on aspects of the car that matter to them (mark), without having to get caught up in the complicated inner workings of the machinery (mark).

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s