Programming Paradigms

Cards (26)

  • Procedural programs perform instructions in sequence, making using of selection, iteration and subroutines
  • Object-oriented programming features objects which can interact and inherit properties
  • Assembly programs use mnemonics and are processor-specific
  • A class consists of a name, attributes and methods
  • A class can be reused to create multiple objects that share the same properties
  • Creating an object using a class template is called instantiation
  • A constructor is a special method within a class that is used to create an instance of that class
  • Classes can inherit properties from other classes, and add additional attributes and methods to them
  • Classes can inherit from classes that inherit from other classes
  • A class can override methods it inherits to do something different
  • To inherit in C#, use :
    For example, Car : Vehicle, where car is inheriting from vehicle
  • Encapsulation means attributes and methods of one object are protected, so they can't be altered by other objects
  • To allow attributes to be changed, a setter can be made public; it may provide restrictions on how attributes can be changed
  • Typically the base class method will override a derived class method if they share the same name
  • In C#, if a base class method is virtual, it can be overridden if a derived class method uses the keyword override
  • Polymorphism means objects can be processed differently depending on their class - they may have the same base class but operate differently using the same method
  • Inheritance is used for 'is a' relationships, eg a cat is an animal, a car is a vehicle
  • Association refers to 'has a' relationships, eg a team has a player, a hotel has a room
  • Aggregation refers to when a class is a container of contained classes, but these do not have a strong dependency on the container and will continue to exist if the container is destroyed, eg a player will still exist if their team disbands. There will be a clear diamond next to the container class
  • Composition refers to when a class is a container of other classes which have a strong dependency on the container. If the container is destroyed, the contained classes will be destroyed as well, eg a room cannot exist if the hotel it is in is destroyed. There will be a solid diamond next to the container class
  • Favour composition over inheritance - composition allows greater flexibility, and an object could be composed of other objects but that doesn't mean they inherit characteristics
  • Encapsulate what varies - classes should be subdivided if there is any variance in them; this is easier to maintain and reduces the need for testing
  • Program to an interface, not implementation - focusing on the 'what', not the 'how'. If classes must all do similar things but are unrelated, we can use an interface to declare capability, and then write class-specific code when this is implemented
  • The structured approach is the process of dividing a big problem down into smaller problems
  • Hierarchy charts can represent the structured approach - the bottom levels will represent single tasks that the program must complete, which add together to create the entire program
  • The structured approach allows for development to be split over a team, and for individual parts of the program to be tested independently