Object orientated design Flashcards
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
What is a memento pattern?
Allows us to track the state of the object externally, without knowing all details of that state
Encapsulate the change into an object of the dedicated class- ie the memento
Allows to capture and externalise object’s internal state without breaking encapsulation
Cons- shape’s state could include a lot of data, when managing multiple shapes need to maintain which memento is for which shape
What is Model-View-Controller (MVC)?
The common pattern that separates the data, its presentation and the way it is manipulated by the user
• Model – an abstraction of the data that provides ways of accessing and manipulating it
• View – presents a specific purpose view onto the Model, captures User’s input and passes it on to the Controller
• Controller – interprets User’s input and invokes corresponding actions on the Model
What’s the difference between passive and active mode?
PASSIVE: the Controller is the only class that affects the Model ACTIVE: the Controller is NOT the only class that affects the Model- the model is a subject and maintains a list of observers, the view implements the observer interface
What are the benefits of classes and objects?
Help managing complexity
- allow us to describe complex systems through meaningful abstractions
- support different level views of the system (eg conceptual- high level abstraction, and implementation- low level abstraction)
- allow all project members to have shared understanding of the system