Chapter 4: Creating Flexible Interfaces Flashcards
What is an interface?
An interface is the means objects use to talk. Design deals not only with what objects an object knows (its responsibilities) and who the object knows (its dependencies) but also how it talks to another.
Mention two concepts on how we can uses an interface
It can refer to:
- The methods within a class and their public or private exposition
- The one that spans across classes and that is independent of any single class. In this sense an interface is a set of methods that define it.
What are the features of the public interface of a class?
- Reveal its primary responsibility
- Are expected to be invoked by others
- Will not change in a whin
- Are safe for others to depend on
- Are thoroughly documented in the tests
What are the features of the private interface of a class?
- Handle implementation details
- Are not expected to be sent by other objects
- Can change for any reason whatsoever
- Are unsafe for others to depend on
- May not even be referenced in the tests
What is a public interface within the class?
It is a contract that articulates the resposibilities of the class.
What is the relationship between Single Responsibility approach and the public interface?
Methods in the public interface of a class should read like a description of responsibilities.
What is the relationship between Managing Dependencies and the class’ interface?
The idea of depends on classes that change less than yours do can be applied to the methods in a class. Methods in the public interface are stable and private ones have more likelihood of change.
What are Domain Objects?
They are classes that are easily identified in the requirements because they are nouns in the application that have both data and behavior. They stand for big, visible real-world things.
Why message-based perspective is better than class-based ones?
Message-based perspective yield more flexible applications than class-based perspective.
Why the sequence diagram is suitable for the message-based design?
The sequence diagram allows checking the interaction between objects and the messages passed between them.
Why is it important to ask for “What” instead of telling “How”?
The “What” allows to create reusable classes with well-defined public interfaces.
What is the context of a class?
The things a class know about other objects make up its context.
Why does a context is important?
The context that an object expect has a direct effect on how difficult it is to reuse. Object with a simple context are easy to use and test.
What does seeking context independence means?
It means creating objects with a simple context where they aren’t holding onto other objects.
What does trusting other objects means?
It means thinking about what instead of how. When we trust another object will do its work, we can just ask (the what) the things we want and the context will be much simplier.