The framework code calls the customized/specific code, not the opposite.
Gerson Sunyé
Gerson Sunyé gerson.sunye@univ-nantes.fr
Introduction.
Properties
Design Principles
A toy example
Correlated concepts
Real-world examples
Conclusion
A software framework is a reusable, "semi-complete" application that can be specialized to produce custom applications.
A set of classes, abstract classes and interfaces.
A set of behaviors, spread over these classes.
An incomplete application for a family of products.
A set of hooks, where subclasses can insert their specialized behavior.
The expectations placed upon the subclasses.
A logic decomposition of a problem.
Represented by its source code.
Modifying working examples.
Creating subclasses.
Configuring objects.
Writing configuration files.
Writing programs/scripts for a domain-specific language.
Modifying a model@run.time.
Reuse: code, design, domain analysis, and documentation.
Simplify software development.
Reduce code writing.
Allow inexperienced designers and programmers to develop good software.
Extract the knowledge of experimented designers and programmers.
Modularity
Reusability
Extensibility
Inversion of control
Dependency inversion
Open-Closed
Abstract classes have a stable interface that encapsulates volatile implementation details.
They provide hotspots or "points of planned variability", where the behavior can be extended.
Design and implementation changes are limited to these points, reducing the effort to understand and maintain the software.
The stable interfaces define generic components that can be extended to create new applications.
Reuse of framework components improves developer productivity, as well as software performance, reliability, and interoperability.
A framework enhances extensibility by providing explicit hook methods for planned variability.
Extensibility is essential to ensure rapid customization of new application features.
In a framework, the flow of control is not dictated by the callers, but by the framework itself (the abstract classes).
The inversion of control enables canonical application processing steps to be customized by hotspots.
The Inversion of Control is also called "The Hollywood Principle"
— Don’t call us, we’ll call you!
The framework code calls the customized/specific code, not the opposite.
High-level modules should not depend upon low-level modules. Both should depend upon abstractions.
Abstractions should not depend upon details. Details should depend upon abstractions
The framework is open for extension and closed for modifications
The source code is supposed to be extended, not modified.
Template Method Pattern
Annotations
Dependency Injection
Hook and template methods are the building blocks of software frameworks.
They allow the implementation of commonality and variability.
A template method defines the skeleton of an algorithm, deferring some steps to subclasses.
Subclasses can redefine some steps without changing the algorithm’s structure.
public void openDocument(String name) {
if (!canOpenDocument(name)) {
// cannot handle this document
return;
}
Document doc = doCreateDocument();
if (doc != null) {
docs.add(doc);
aboutToOpenDocument(doc);
doc.open();
doc.doRead();
}
}
concrete Client operations.
concrete AbstractClass operations (i.e., operations that are generally useful to subclasses).
concrete operations..
abstract operations.
factory methods (see Factory Method Pattern).
hook operations, which provide default behavior that subclasses can extend if necessary. A hook operation often does nothing by default.
A hook method represents a point of variability by providing the calling interface to a variable behavior.
Each implementation of a hook method provides a variant of that behavior.
An annotation[1] is a technique to provide meta-data on a programming element: classes, methods, fields, etc.
The meta-data can be used to add additional behavior to the programming element.
@Component
public class ChatModule {
@Autowired
public ChatModule(SocketIOServer server) {}
}TestCase starting with "test"@TestDependency Injection is a set of software design principles and patterns that enable us to develop loosely coupled code
Dependency Injection helps developers to respect the Dependency Inversion Principle
It allows the choice of concrete classes to be made at run-time, rather than at compile time
The Risk Server should only depend on the Board Repository
However, Risk Server must instantiate the class Hibernate Board Repository,
creating a dependency to a concrete class.
Find all the dependencies for Risk Server
Find all implementation of Board Repository
Instantiate Hibernate Board Repository and assign the instance to Risk Server
Use reflection to find fields with a specific decorator (e.g. @Inject) and get its type
Use reflection to find an implementation of the previous type
Instantiate the type and use reflection (again!) to assign the new instance to the field
Bouncing-Bumping Games


Game::makeWorld() {
makeBouncer();
makeControllers();
makeObstacles();
makeEventHandlerTable();
}
Game::run(){
loop over event e in eventQueue {
ehTable[e]-> handleEvent(e);
refreshDisplay(); }
}The developer designs the application, decomposes the problem and specifies the flow of control.
The application calls the library.
The developer extends the framework. The framework defines the flow of control and design decomposition.
The framework call the extension code.
describe micro-architectures
are abstract
have concrete architecture and code.
incorporate design patterns, often to provide extension points (variability).
are a rich field for design pattern mining.
describe abstract macro-architectures.
target whole systems, but can be used for a product line and single applications.
are design artifacts.
are designed to ensure software quality.
describe the guiding principles behind a given application.
are concrete implementation of abstract architectures.
are designed to be specialized/customized.
focus on reusability.
Smalltalk MVC (Model View Controller). 1980
Microsoft Windows Presentation Foundation (WPF). 2006. Language: C#
macOS Cocoa AppKit. 1996. Languages: Objective C, Swift,
Provide a standard and generic software foundation.
Examples: COM, CORBA, Java J2EE, ACE (Adaptive Communication Environment, Doug Schmidt et al).
Baan: Enterprise Resource Planning (ERP) software written in Java.
San Francisco Business Objects (Taligent/IBM).
The Oracle Enterprise Architecture Framework.
Zope (Zope Corporation) — Python.
Apache Struts — Java.
Django, Ruby on Rails, Symfony, Yii, Spring MVC, Stripes, Play, CodeIgniter, etc.
Angular, ViewJS, ReactJS
Hotspots: planned extension points.
Inversion of control: the framework controls the application and not the opposite.
Learning curve.
Important initial investment.
Framework developers must be domain experts.
Framework evolution is complex.
Code and design reuse.
Perspective shift: programmers are forced to write reusable software.
Improvement of software quality and developer productivity.
M.E. Fayad, D.C. Schmidt, R.E. Johnson, “Building Application Frameworks”, Addison-Wesley, 1999.
Object Oriented Frameworks. Greg Butler. Ecoop 2001 Workshops.