Skip to main content

Topic 1

Topic 1 has 3 parts: Objects, Features, and some info about encapsulation and abstraction.


Introducing Objects

  • "Computers are dumb"

  • Software development is defining instructions to computers

  • Programs are made from a range of artefacts to help against complexity.

    • This is when we split our program into procedures and functions
  • Object Oriented Programming uses a collection of objects

    • Objects are basically just "concepts"

    • Objects can do actions and "knows things"

    • They can store different values and have different name

  • Objects have their own functions/actions

    • Functions are called methods
  • As they act as themself, you may have something like:

    player.attack(monster);

        Where player and monster are objects, and attack() is a method.

Some encapsulation stuff

  • When we make objects, we create entities that encapsulate both the data and functions (function being the actual abilities of the object). This is what they mean when they say that objects "know and can do things".

  • Programs are build on multiple objects that interact with each other in order to produce a final outcome.

  • Each object has it's own set of accessible and inaccessible components

    • There's the "private" access part, and the "public" access part.

      • We've done this when coding already

Some abstraction stuff

  • Talking about which ideas need to be captured

  • Mapping of concepts to objects

  • Getting a real world thing, such as a "player" in a game, and creating a Player class around it, and so on.

  • Breaking things down into core ideas and characteristics

  • Figuring what a thing needs to have and what it needs to be able to

    • Not HOW, but WHAT.
  • It's literally planning out the objects and stuff

  • A good way to do this is to consider both it's private and public sections (What it knows and what it can do)

    • A player object might know it's health, it's location, and it's name (what it knows). It might have methods to move, and attack.

    • We basically repeat this until we have multiple objects planned / defined in sets of related "knowledge" and "methods".

    • Then we consider how these objects interact.

      • Think about what they do to each other - an enemy archer may create arrow objects.

      • Some variables may need to be public

This should give you a good run down though.

  • Abstraction is used to define object classes

  • It includes generalisation and specialisation

    • Think about the Shape class in ShapeDrawer. Think about how rectangles, trianges, and circles are all by definiton... shapes.

    • With this in mind, we can create families of classes

Features of an OO Language

This part of mainly about creating a class. The steps (which don't have to be followed in exact order) are as follows:

  1. Define a class that meets the specifications of the object

  2. Add the private fields, for example:

    private string _name;
  3. Add a constructor

    • This is basically a method with the same name as the class, you use this to initialise the object.
  4. Add methods (these are your functions/capabilities), for example:

    public void AddPoints(int num1)
    {
    int _score = _score + 1 * ScoreMultiplier
    }
  5. Add properties to make the private data accessible externally, for example:

    public int Score
    {
    get{return _score; }
    set{_score = value;}
    }
caution

There was a Topic 01 - Part C but it was a video demonstration of a "card" program. You may wish to watch that in your own time.