The first trail is a basic intro into Object-Orientated Programming Concepts.

  • Object – a bundle of related state (Fields) and behaviour (Methods), use data encapsulation to hide internal state, and force interaction through methods.
    • Benefits:
      • Modularity : Independent source code. Pass object around system
      • Information-hiding : hide internal implementation details
      • Code re-use : reuse objects, implement/test/debug objects
      • Pluggability and debugging ease
  • Class – models state and behaviour of real-world object.
  • Inheritance – subclass extends state and behaviour from superclass.
  • Interface
    • if a class implements an interface it must implement all methods defined in the interface.
    • inherently static
  • Package – namespace for organising classes and interfaces.

and then some exercises…

Questions

  1. Real-world objects contain state and behaviour.
  2. A software object’s state is stored in fields.
  3. A software object’s behaviour is exposed through methods.
  4. Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data encapsulation.
  5. A blueprint for a software object is called a class.
  6. Common behaviour can be defined in a superclass and inherited into a subclass using the extends keyword.
  7. A collection of methods with no implementation is called an interface.
  8. A namespace that organises classes and interfaces by functionality is called a package.
  9. The term API stands for application programming interface?

Exercises

  1. Create new classes for each real-world object that you observed at the beginning of this trail. Refer to the Bicycle class if you forget the required syntax. Speaker.java, SpeakerDemo.java : PowerOn = true, Volume = 3, MegaBassOn = true
  2. For each new class that you’ve created above, create an interface that defines its behaviour, then require your class to implement it. Omit one or two methods and try compiling. What does the error look like?
public interface Speakers {
void turnOn();
}

With no turnOn() method in the Speaker class:

Speaker is not abstract and does not override abstract method turnOn() in Speakers

With no public turnOn() method in the Speaker class:

turnOn() in Speaker cannot implement turnOn() in Speakers
attempting to assign weaker access privileges; was public

 

 

Advertisements

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