i am studying for an exam , and some questions in the exam they give as a particular specification of a classes and ask as what design patterns are used in the code , i learned all of the design patterns , and i think i understand them , but i can't figure out how to solve such a questions ? any tips on how to become good at solving these quesions ? examples for such questions : let's say i have an android operating system , that was written in java , we have a view class and and a ViewGroup class that represent graphic objects for GUI , here is a part of the specification for those classes , i want to know which design patterns were used in this code
// This class represents the basic building block for user
// interface components. A View occupies a rectangular area on
// the screen and is responsible for drawing and event handling.
// View is the base class for widgets, which are used to create
// interactive UI components (buttons, text fields, etc.).
class View implements Drawable.Callback, KeyEvent.Callback,
AccessibilityEventSource
// A ViewGroup is a special view that can contain other views
// (called children).
abstract class ViewGroup extends View implements ViewParent,
ViewManager
a. Adapter and-Observer
b. Composite and-Observer
c. Composite and-Adapter
d. Decorator and -Observer
e. Decorator and -Adapter
any help ?
or another example :
let say we have we have a logger class that saves log info , and for example the NtfsFileSystem describes the NTFS file system . which design pattern in violated in here ?
class Logger {
private NtfsFileSystem fileSystem = new NtfsFileSystem();
private String logFilename;
public void log(String text) {
fileStream = fileSystem.openFile(logFilename);
fileStream.write(text);
fileStream.closeFile();
}
…
}
is it : Creator , encapsulation , Dependency inversion principle , law of demeter or liskov substitution principle ?
Aucun commentaire:
Enregistrer un commentaire