Object orientated design Flashcards
(28 cards)
What is object orientated programming?
a method of implementation in which programs are designed as cooperative collections of objects
- describing a system in terms of meaningful abstractions (classes), relationship and interactions between them
- allows us to understand the requirements and design a solution on the conceptual level
- allows us to design and build extensible solutions and build for change via encapsulation, inheritance and polymorphism
- allows us to communicate ideas and concepts in a clear consistent way to all team members
- works across all stages of the software development process from Analysis to Maintenance via Design and Implementation
What are abstractions?
Generalisations that define certain key characteristics and behaviour
What are abstractions about?
dealing with ideas
generalisation
-to focus on what matters, on key characteristics and behaviour
-to see things even clearer
-to simplify and make complexity manageable
What is a class?
A class represents a key concept within the system and encapsulates data and behaviour
What are objects?
Instances of a class that contain data and behave according to the class definition
What is encapsulation?
Exposing WHAT an object does and not HOW it works- designer can later improve the object without changing how the user interacts with it
‘defining functionality necessary for the objects to be used and hiding the details of how this functionality is implemented’
Why do we use encapsulation?
- hide (abstract away) implementation
- reduce dependencies between different parts of the application
- make changes more safely/grow software more easily
- debug more easily
- examine the system from different levels
- make everything more manageable
What do classes provide?
Abstractions (complimentary to encapsulation)
What are getters and setters?
Properties Provide controlled access to internal data fields If access to internal data fields of the class is not controlled we can't do any of the things that encapsulation allows
What is inheritance?
Subclass points with a white arrow to the superclass Subclass is type of superclass eg triangle is a shape Subclass extends the data and behaviour of superclass
What is polymorphism?
Allows us to request the same action from objects yet execute it in different ways- useful for extensibility, can generalise operations on similar concepts yet support distinct data and behaviour where necessary
What is an abstract class?
A class that can't be instantiated- conceptual capture the higher level view of the system Any class with an abstract method is declared an abstract class
What is an interface?
A purely abstract class that defines only behaviour (not data) eg iSubmersible, dive class will extend one superclass but will implement multiple interfaces dotted line white arrow
What is UML?
A formal graphical language comprising a set of diagrams for describing software systems
Diagram made of structure diagrams (class, show relationships) and behaviour diagrams (sequence, how they interact)
What is the most common mode of UML?
“AsSketch”
what is 0 or more?
0..*
What is the block structure in a class diagram?
class name, data/attributes, behaviour/operations
What is an association?
A line between classes
What are compositions and aggregations?
Composition- filled diamond
A<>-B B can’t exist without A, eg rooms in house
Aggregation- empty diamond
B is a part of A but can exist without it, eg members of society
What are communication diagrams?
Another type of behaviour diagram which show the method flow between objects by numbering method calls
-good for few method calls between potentially many objects
What is pattern structure?
- Motivation- outline specific functionality that software should provide
- Solution options- explore ways of providing this functionality and discuss their limitations
- Optimal solution- present preferred solution based on a design pattern
- Code example- an example of what the design solution looks like using any programming language
- Design pattern- discuss the general principle underlying a good solution and its applicability to other situations, show the generic design pattern using UML
- Disadvantages- discuss the shortcomings of the design pattern and why you might not want to use it for certain cases
What is a composite pattern?
Want to operate on individual items and groups of those in a common way
Cons: can be too general, client code must be able to distinguish between composite objects and non-composite objects
What is a decorator pattern?
Allows us to add functionality without changing the original class
- If there are not too many kinds of added functionality and they appear fairly commonly, it may be more convenient to use solution 1 (add attribute in class)
- Hard to resolve the identity of the objects we are dealing with since decorator is a distinct object from the component it decorates- in a running system this can result in long chains of small objects that point to each other, making the software hard to debug
What is an observer?
Allows multiple objects to maintain a consistent view on the state of the object of interest
cons- could lead to large computational overhead if not safeguarded