This course discusses Object-Oriented Design and Analysis. This course focuses on the fundamental ideas that make up object-oriented programming (OOP, for short). You will design a simple object oriented program according to object-oriented principles and learn how to document your object oriented designs using uml diagrams.
To design an object-oriented program in alignment with object-oriented principles, one must adhere to the core tenets: encapsulation, abstraction, inheritance, and polymorphism. The design process involves several methodical steps:
- Define the Domain Model:
Identify the problem domain and define the entities (objects) along with their attributes and behaviors. These entities represent the real-world elements relevant to the system.
- Apply Encapsulation:
Group related data and behaviors (methods) into classes, ensuring that each class represents a single concept or entity. Encapsulation hides the internal state of objects and exposes only what is necessary through a well-defined interface.
- Implement Abstraction: Abstract classes and interfaces to define generic templates that represent conceptual entities, highlighting essential features while omitting implementation details. This promotes the concept of 'programming to an interface' rather than to an implementation.
- Utilize Inheritance: Organize classes into hierarchies where subclasses inherit properties and behaviors from parent classes, facilitating code reuse and the creation of more specific subclasses from a general description.
- Embrace Polymorphism: Design classes in such a way that they can be interchanged, meaning that they can be used through their interface without the need for the user to be aware of the exact class type. This enables multiple objects to be treated as instances of their parent class rather than their actual class.
- Identify Relationships:
Determine how objects will interact and reference each other. These relationships can be associations (plain interaction), aggregations (whole-part), or compositions (strong whole-part).
- Define Object Collaborations:
Design the interactions between objects to complete operations or functions, ensuring each object's role in the collaboration aligns with its responsibilities.
- Apply Design Patterns:
Incorporate established design patterns where appropriate to solve common design problems. Patterns like Factory, Singleton, Observer, Strategy, and others can provide ready-made solutions that are both robust and reusable.
- Review and Refine:
Iteratively refine the model, applying the SOLID principles (Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion) to improve the design.
UML (Unified Modeling Language) diagrams are used to visually represent and document the design of object-oriented systems. The key UML diagrams include:
- Use Case Diagrams: Illustrate the functional requirements of the system, depicting the interactions between users (actors) and use cases.
- Class Diagrams: Detail the classes within the system, their attributes, operations, and the relationships among them, such as inheritance, association, aggregation, and composition.
- Sequence Diagrams: Show object interactions in a time sequence, illustrating how objects collaborate with each other in a particular scenario.
- Activity Diagrams: Represent workflows from one activity to another, highlighting the sequence of actions and control flows within the system.
- State Diagrams: Describe the state changes an object undergoes in response to events, reflecting the dynamic behavior of the system.
- Component Diagrams: Depict the organization and dependencies among a set of components, showing how software code maps onto the operational environment.
- Deployment Diagrams: Outline the physical deployment of artifacts (software systems) on nodes (physical hardware).
- To document a design using UML, one must:
- Select the appropriate UML diagram type based on the aspect of the system to be visualized.
- Use standardized UML symbols and notation to represent the entities and their relationships.
- Arrange the elements in a clear and logical manner, avoiding clutter, to ensure readability and comprehension.
- Iterate and refine the diagrams in tandem with the evolving design.
Proper documentation using UML diagrams facilitates a clear understanding among stakeholders, provides guidance for developers during implementation, and serves as a reference throughout the software development lifecycle.
After completing this course, you will be able to create design specifications that demonstrate the essentials of OOP, including:
- How classes allow programmers to define their own data types
- How messages are passed between objects with methods
- How to separate interfaces from implementation using access protection
- How to guarantee that variables are initialized with constructors
- How to reuse code via inheritance
- How polymorphism allows the same message to be sent to different objects
We are going to to discuss analysis, where the goal is to understand a problem. Actually, there are two kinds of things we
need to think about at this point.
- Application analysis: Application analysis is concerned with understanding the requirements of a particular problem.
a) The development of use cases, falls into this category. We seek to understand how someone will use our software. b) The specification of initial functional tests likewise falls into this category. Spelling out such tests helps us to better understand what must take place.
- Domain analysis: Domain analysis is concerned with understanding the particular application domain of which a
specific problem is a part. For example, if you were developing a system involved with student registration for courses, the domain you would need to be
familiar with includes concepts like students, courses, course offerings, sections, enrollments etc.; as well as the relationships between them.
In the next lesson, the prerequisites for the course including C++ and Java will be discussed.
In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.
For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results.
Polymorphism: is considered to be a requirement of any true object-oriented programming language(OOPL).