Question

A software design pattern is a general, reusable solution to a commonly occurring problem, acting as...

A software design pattern is a general, reusable solution to a commonly occurring problem, acting as a description or template for how to solve a problem: it is not a finished (complete) design that can be directly translated into source code. Patterns exhibit varying levels of abstraction, varying from very abstract approaches to very specific. What does the acronym MVC stand for, what is its level of abstraction, and what problem does it solve? What is the singleton pattern, what is its level of abstraction, and what problem does it solve? Describe how the use of recognized patterns is beneficial in the context of: Designing new software components Performing reverse engineering on existing software.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MVC

Model-View-Controller(MVC) is a programming design pattern which was created to solve the design problem of a rather frequent application: Displaying data to the user (and possibly handling input from the user).

The basic idea of this pattern is to divide the program (or module) into three main modules: The Model, the View and the Controller(as shown in the figure1). In its purest form, the MVC pattern works like this:

  1. The Model is, simply put, the module which handles the data of the program. It could be, for example, a module which interacts with a database. In its simplest form it could simply be some kind of data container (such as a list), depending on the application.

    The Model module has no functionality on its own other than as an interface between the data and the rest of the program. It handles the data only to the extent that is needed for it to be stored and restored but otherwise doesn't make any decisions about what to do with the data.

  2. The View is the module whose task is to display data to the user. It does not have any functionality in itself, other than what is needed to transform and lay out the data as needed by the display format. In other words, the View acts as an interface between the display (which can be a physical display or eg. a document format) and the rest of the program, and doesn't have any functionality related to anything else than displaying the data.

  3. The Controller is the core module which makes all the decisions. It has all the relevant functionality of the program and interacts with the Model and the View, commanding them and passing data between them as needed.

There are two schools of thought with regard to whether the View interacts directly with the Model or not. In one school of thought the View and the Model are completely separate and have no connection whatsoever. All the data between the two is handled by the Controller. In the other school of thought the Controller can command the View to retrieve data from the Model so that the data doesn't have to be transferred by the Controller. (This naturally creates a dependency between the View and the Model.) In other words, the functionality of the View is enhanced as much as is needed for it to interact with the Model in order to retrieve data (but otherwise the View has no functionality of its own.)

Case example

A perfect example of where the MVC pattern is useful is a web server:

  1. The Model is the module which interacts with the database (in the simplest designs this could be directly the library which is used to query the database using eg. SQL).
  2. The View is the module which generates HTML from the data.
  3. The Controller contains all the other functionality of the server (eg. it decides which page to display, generates dynamic content, handles session and cookie data, etc.)

One would hastily think: "Don't all web servers actually do exactly this (at least those which produce dynamic content)? Isn't this pattern rather ubiquitous?"

The answer is no: The critical element which distinguishes the MVC pattern from a non-MVC design is the separation between the View and the Controller. They must be completely separate and independent modules. If the Controller outputs HTML directly (which is extremely usual), then it breaks the MVC pattern because now there is no abstraction between the functionality of the Controller and the output that the program produces.

Level of abstraction

Single Level of Abstraction

Singleton Pattern

Singleton is a part of Gang of Four design pattern and it is categorized under creational design patterns.It is one of the most simple design patterns in terms of the modelling but on the other hand, this is one of the most controversial patterns in terms of complexity of usage.

Singleton pattern is a design pattern which restricts a class to instantiate its multiple objects. It is nothing but a way of defining a class. Class is defined in such a way that only one instance of the class is created in the complete execution of a program or project. It is used where only a single instance of a class is required to control the action throughout the execution. A singleton class shouldn’t have multiple instances in any case and at any cost. Singleton classes are used for logging, driver objects, caching and thread pool, database connections.

Implementation of Singleton class

An implementation of singleton class should have following properties:

  1. It should have only one instance : This is done by providing an instance of the class from within the class. Outer classes or subclasses should be prevented to create the instance. This is done by making the constructor private in java so that no class can access the constructor and hence cannot instantiate it.
  2. Instance should be globally accessible : Instance of singleton class should be globally accessible so that each class can use it. In Java, it is done by making the access-specifier of instance public.

Applications of Singleton classes

There is a lot of applications of singleton pattern like cache-memory, database connection, drivers, logging. Some major of them are :-

  1. Hardware interface access
  2. Logger
  3. Configuration File
  4. Cache

Important points

  • Singleton classes can have only one instance and that instance should be globally accessible.
  • java.lang.Runtime and java.awt.Desktop are 2 singleton classes provided by JVM.
  • Singleton Design pattern is a type of creational design pattern.
  • Outer classes should be prevented to create instance of singleton class.

Add a comment
Know the answer?
Add Answer to:
A software design pattern is a general, reusable solution to a commonly occurring problem, acting as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT