Preview

05 - Abstraction

 1. Abstraction is about pulling out the key features of a system and ignoring _________________________
This video from www.teachyourselfpython.com provides a vivid explanation of abstraction with coded examples

  the essentials

  the code

  irrelevant details.

  object orientated programming

 2. Abstraction is one of the key features of OOP.

  False

  True

 3. How has abstraction been used in the following example?
class Car(object):

    wheels = 4

    def __init__(self, make, model):
        self.make = make
        self.model = model

mustang = Car('Ford', 'Mustang')
print mustang.wheels
# 4
print Car.wheels
# 4

  Abstraction has been used in line 1 where the class has been given a name -"object"

  It has not been used

  The class has been created with attributes make and model. These are the relevant details and the irrelevant ones have been left out.

  wheels = 4. Abstraction is the use of numerical values instead of text

 4. In the following example (in Java) abstraction has been provided by the …..
import org.thoughts.on.java.coffee.CoffeeException;
import java.util.HashMap;
import java.util.Map;

public class CoffeeApp {
    public static void main(String[] args) {
        // create a Map of available coffee beans
        Map<CoffeeSelection, CoffeeBean> beans = new HashMap<CoffeeSelection, CoffeeBean>();
        beans.put(CoffeeSelection.ESPRESSO, 
            new CoffeeBean("My favorite espresso bean", 1000));
        beans.put(CoffeeSelection.FILTER_COFFEE, 
            new CoffeeBean("My favorite filter coffee bean", 1000));

        // get a new CoffeeMachine object
        CoffeeMachine machine = new CoffeeMachine(beans);

        // brew a fresh coffee
        try {
	    Coffee espresso = machine.brewCoffee(CoffeeSelection.ESPRESSO);
	} catch(CoffeeException  e) {
	    e.printStackTrace();
        }
    } // end main
} // end CoffeeApp

  CoffeeMachine class which hides all the details of the brewing process

  None of the above

  Map function. It's job is to ensure not a single detail is left out

  beans.put method - which creates beans and instances of objects

 5. The brewFilterCoffee and brewEspresso methods ____________ the specific operations required to brew the coffee. All that is needed is to know how to call the methods
private Coffee brewFilterCoffee() {
    Configuration config = configMap.get(CoffeeSelection.FILTER_COFFEE);
  	
    // grind the coffee beans
    GroundCoffee groundCoffee = this.grinder.grind(
        this.beans.get(CoffeeSelection.FILTER_COFFEE), config.getQuantityCoffee());
  	
    // brew a filter coffee
    return this.brewingUnit.brew(
        CoffeeSelection.FILTER_COFFEE, groundCoffee, config.getQuantityWater());
}

  cataract

  abstract

  detract

  delete

 6. Another definition of abstraction in object orientated programming is that it hides the internal details/complexity from the user.

  FALSE

  TRUE

 7. Abstractions (e.g. making several classes) make it a lot easier to handle complexity by splitting them into smaller parts

  FALSE

  TRUE

 8. Abstraction is said to….

  increase efficiency

  ignore the irrelevant details

  reduce complexity (hide it from the user)

  All of the above

 9. Abstraction is related to both encapsulation and data hiding.

  FALSE

  TRUE

 10. Abstraction is one of the most important principles in object-oriented software engineering and is closely related to several other important concepts, including ….

  None of the above

  CPU training and non-object coding

  using irrelevant details and hard work

  encapsulation, inheritance and polymorphism.