Object-Oriented Programming
Object-oriented design and programming in Java, with Python and C++ comparisons: from procedural code to objects, classes, encapsulation and immutability, constructors, object lifetime, garbage collection and RAII, composition and aggregation, inheritance and the Liskov substitution principle, polymorphism, dynamic dispatch and vtables, abstract classes and interfaces, exceptions and exception safety, generics, templates and the collections framework, the SOLID principles, creational, structural and behavioural design patterns, UML class, sequence and state diagrams, and unit testing, test doubles and refactoring, ending with the refactoring of a legacy traffic-data server.
CMP-220 Year 2 3 credits 12 lessons · 4 h 9 min ▶ Video lessons coming soon
Offered by HSM University · Computer Engineering
This is the Canadian version of this course. See the American version.
What you'll learn
- Explain how object-oriented programming differs from procedural programming, and identify candidate classes, fields and methods from a written requirement.
- Write classes with private fields, validating constructors and intention-revealing methods that enforce invariants, including immutable classes, records and data classes.
- Describe object lifetime in Java, Python and C++, including references and aliasing, identity and equality, garbage collection, memory leaks, try-with-resources and RAII.
- Model has-a relationships as association, aggregation or composition, draw them in UML with multiplicities, and implement them with delegation and constructor injection.
- Use inheritance to express substitutable is-a relationships, chain constructors, override methods correctly, and recognize violations of the Liskov substitution principle.
- Explain static and dynamic types, dynamic dispatch and vtables, distinguish overloading from overriding, and replace type-code conditionals with polymorphism.
- Design contracts with abstract classes and interfaces, apply the template method pattern, and program to interfaces in Java, Python and C++.
- Design exception hierarchies, throw and handle exceptions at appropriate boundaries, chain causes, and apply exception-safety guarantees and idempotent operations.
- Write and use generic classes and methods with bounds and wildcards, explain type erasure and C++ template instantiation, and choose collections from their underlying data structures.
- Apply the SOLID principles and composition over inheritance, and use factory, builder, adapter, composite, decorator and facade patterns where they fit.
- Apply the strategy, observer, state and command patterns, and model object lifecycles with UML state machine and sequence diagrams.
- Write fast, isolated unit tests with test doubles, use test-driven development and characterization tests, and refactor legacy code in small, verified steps.
Course content
12 lessons · 4 h 9 min total · final exam
- 1 Why objects: from procedural code to objects 21 min · quiz
- 2 Classes, objects and encapsulation 20 min · quiz
- 3 Constructors, object lifetime and memory 22 min · quiz
- 4 Composition and aggregation 21 min · quiz
- 5 Inheritance 20 min · quiz
- 6 Polymorphism and dynamic dispatch 21 min · quiz
- 7 Abstract classes and interfaces 21 min · quiz
- 8 Exceptions and error handling 21 min · quiz
- 9 Generics, templates and collections 21 min · quiz
- 10 SOLID principles and creational and structural patterns 20 min · quiz
- 11 Behavioural design patterns 21 min · quiz
- 12 Unit testing, test doubles and a refactoring capstone 20 min · quiz
- E Final exam 20 questions
Requirements
Recommended background. You can start any course at any time.
Description
Object-oriented design and programming in Java, with Python and C++ comparisons: from procedural code to objects, classes, encapsulation and immutability, constructors, object lifetime, garbage collection and RAII, composition and aggregation, inheritance and the Liskov substitution principle, polymorphism, dynamic dispatch and vtables, abstract classes and interfaces, exceptions and exception safety, generics, templates and the collections framework, the SOLID principles, creational, structural and behavioural design patterns, UML class, sequence and state diagrams, and unit testing, test doubles and refactoring, ending with the refactoring of a legacy traffic-data server.
Part of the Engineering stream, typically taken in year 2.