Week 5 Flashcards
What is object orientated programming
It is a programming paradigm based on concept of objects which are instances of classes
Objects contain:
data - attributes / properties
code - methods / functions
What is Object-Orientated design
process of designing a software solution using OOP
what are method signatures
Each method has signature : name, parameters, return type and access level.
What are key ideas related to object calling and answering
objects interact by calling methods, but not just any, only predefined methods
They don’t accept arbitrary calls
Methods define acceptable calls
What is an object interface
This is the set of method signatures available for the object
example arrays have .index or .get or whatever but you don’t actually know wtf happens behind the interface.
explain information hiding or encapsulation regarding Object interfaces
Involves hiding their internal attributes and only allowing access through interface methods.
client and server objects
client = object requesting something
server = the object fulfilling it by like doing the function
scenario based obvs
when object calls a method on another object its like sending a message “ hey poes do this”
Modules vs objects
modularity is more for just organising code by grouping functionality together
objects is similar but encapsulates data
What are UMLs
- Unified Modelling Language
Standardised visual language which represents different aspects of a systems structure and behaviour
similar to ERDs
Key components of a UML
Class diagrams
Use case diagrams
Sequence diagrams
Activity diagrams
State machine diagrams
Component Diagrams
Deployment diagrams
Package diagrams
UML classes has 3 compartments
Class Name
Attributes
Operations
symbols with operations in UML classes
+ public - Accessible from anywhere (any class can use it).
- private - Only accessible within the class itself (not from other classes).
protected # - Accessible from the same class and subclasses (but not outside them).
~ package - Accessible only within the same package/module (used in Java, not in Python).
/ derived - Represents a calculated (not stored) attribute.
class diagrams
shows classes, attributes and relationships
use case diagrams
different users
sequence diagrams
how objects interact over time
e.g. log into ATMs, requests verification, bank responds
Activity diagrams
shows flow of activities in a system
like online order has
Add to cart
Payment info
Confirm order
State machine diagrams
show how objects move between states
robot go red to green to yellow
Component diagrams
shows software components and their dependencies
web app with its databases, UI and APIs
Deployment diagrams
how software is deployed
Package diagrams
groups classes into packages for better organisation
a large e commerce might have separate packages for User management or payments or order processing etc
UML notation for classes relationships
Association : solid line >
Inheritance : solid line open triangle
implementation : dotted line open triangle
dependency: dotted line >
aggregation : solid line open diamond
Composition : solid line solid diamond
what is association
when object accesses another in some way
owner feeds dog
bidirectional - solid line no arrow
unidirectional - solid line with one arrow
prohibited association - solid lines with two arrows facing each other
Inheritance
object inherits properties of another
“is a “ relationship
composition
object references another object
“has a” relationship
aggregation
similar to composition
composition is more child cannot exist without the parent
aggregation is child can exist without parent
inheritance vs composition in making changes
when you inherit you take all properties so changes in parent affect all children
with composition a class contains an instance of another class so changes in one don’t affect the other
car has engine .
What is polymorphism
its a concept in OOP allowing objects of different types or classes to be treated under a common superclass
We can write code to work with objects of different classes in a uniform way even if they may behave differently
Compile time polymorphism
s when compiler decides which method to use
aka Static or early binding
Done by method loading - methods with same names but different parameters
or even done by operator overloading -operators like + * - can be overloaded to work with custom types exampling adding two fags to make a bigger fag.
Runtime polymorphism
Decision about which method to call is determined during execution of the program
done by:
Method overriding: child redefines a method that is defined by its parent
interface implementation - different classes implement the same interface but with their own implementation
dog bark and cat moos
Duck Typing?
form of polymorphism
This is where an objects type or class is not as important as the methods it has
so if the objects have methods that are expected, it is treated as the type expected even if it doesn’t explicitly inherit from that type.
Imagine you have different animals, like a Duck, a Dog, and a Cat. You don’t care what type of animal they are, as long as they can walk and quack ( make sounds).
So, if you see an animal that walks and quacks, you treat it like a Duck, even if it’s actually a Dog or a Cat. The important thing is what it can do (walk and quack), not what type of animal it is.
Subtyping polymorphism
child inherits from parent
so a child object can be used wherever a parent it used as it has the same attributes.
Ad-hoc polymorphism
This is method or operator overloading such as compile time poly.
poly pros and cons
PROS:
code reusability - generic code can work with different object types
modularity - able to extend functionality without changing existing code
flexibility - can interact with different types without knowing the exact types
CONS:
complexity
readability
performance - dynamic dispatch is slower
Why we use object orientated (pros)
Modularity and reusability make development:
- Easier
- Faster
- More productive
- Cheaper
- easier to maintain
- However, can be complicated to design and explain
How do design OO systems well
Agility (like the scrum process)
Traceability
Testability - TDD
Measurability - stats, reports performance
Security