Design Patterns highlights-full introduction to programmer interviews

Source: Internet
Author: User

Whether you participate in a Java interview or a C # interview, design patterns and software design issues are an essential part of the programmer interview. Programming and design skills complement each other. An Outstanding programmer is also an outstanding designer who knows how to use code to solve problems or software design, but these skills need to be constantly improved. This requires you to constantly maintain the design philosophy, regardless of the size of the programming project, from the failure to sum up experience.

Learning from the object-oriented design principles is a good start. This article summarizes some design issues that are often mentioned during various interviews. This article consists of two parts: one for beginners and the other for intermediate and senior technical personnel.

I. Interview Questions for entry-level programmers:

Most of the problems with these software design and design patterns will occur in the interview scenarios for beginners. What is the design pattern? What is a specific design pattern? You may easily answer these concepts, but the questions provided in the article may bring more value to you.

1. What is the design model? What design patterns are used in your coding process?

Each programmer uses his or her own experiences to answer these specific design questions. The design pattern is an extension of code reuse.

2. Can you tell me some design patterns used in the standard JDK library?

The decorator design pattern is often used in various Java Io classes. The Singleton pattern is often used in the running stage. The calendar and various other classes. The factory pattern is often used in various immutable classes, such as boolean. Boolean. valueof and observer modes are often used in swing and many event listener frameworks.

3. What is the singleton Design Pattern in Java? The Singleton encoding for thread security.

The Singleton mode is primarily the sharing mode in the entire system. Only one specific class is maintained in the entire application instance, which is determined by the module sharing. Java. Lang. Runtime is a typical example of Singleton design patterns. For more information, see. From Java 5, you can use Enum for the secure thread Singleton mode.

4. What are the main advantages of using the factory mode? Under what circumstances will you use it?

The main advantage of the factory mode is that it can improve the encapsulation level when creating objects. If you use the factory mode to create objects, You can reset the device of the initial product in the future or implement more advanced and high-performance classes without any customer layer. You can view more details about the factory mode and its advantages.

5. What is the Observer Design Pattern in Java?

The observer design pattern changes based on object changes. For example, the weather system must present the view of weather changes to the audience. Here, the weather project is the subject rather than the observer. Through this article, you can view the observer mode in Java.

6. An example of using the decorator mode in Java? Is it an object or a class level?

The decorator mode improves the capabilities of individual objects. Java Io widely uses the decorator mode and some classic examples of the buffered type, such as bufferedreader and bufferedwriter, to enhance the reading and writing of readers and writers at the buffer level to improve performance. Learn more.

7. What is the MVC design pattern? Here is an example of MVC design patterns.

8. What is the frontcontroller Design Pattern in Java? Here is an example of frontcontroller design mode.

9. What is the responsibility design model?

10. What is the adapter design pattern? Here is an example of the adapter design pattern in Java.

2. Interview Questions for class-level programmers:

1. For example, when will you use abstract classes and when will you prefer to use interfaces?

This is a common interview question and is not difficult. Both interfaces and abstract classes follow the design principle of "not writing code for implementation" to increase code flexibility and meet changing requirements. The following are some guides to help you answer this question:

  • In Java, you can only inherit one class, but implement multiple interfaces. So when you inherit a class, you can no longer inherit other classes.
  • Interfaces are used to represent adjectives or behaviors, such as Runnable, Clonable, and Serializable. Therefore, if you use an abstract class to implement Runnable and Clonacle, you cannot enable your class to implement both functions at the same time, but if the interface is OK.
  • Abstract classes are a little faster than interfaces, so you should try to use abstract classes for applications that care about time.
  • If the common behavior of multiple inheritance levels is better written in the same place, the abstract class is a better choice. Sometimes you can define a function in an interface, but the default function in an abstract class can work together with the abstract class. Understand Java interfaces.

2. Design a vending machine that can receive different coins and sell different goods.

This is an open design question. You can use it to practice document design, write code, and JUnit unit testing, instead of simply solving the problem. The goal of this question is not just to determine how long you can get a solution. Ideally, a working version should be provided within three hours.

3. You have a Smartphone class and its derived classes, such as iPhone, AndroidPhone, and WindowsPhone, as well as derived classes named after the brand name, such as SonyPhone. How do you design such a system?

This is another practice of design patterns. You fully utilize object-oriented design techniques to ensure that they are flexible enough to support new products and ensure sufficient stability when the existing model changes.

4. When should I use overload and override in Java?

This is a very simple problem for experienced designers. Both the overload and overwrite functions implement the same function in Java, but the input variables of overload are different, and the override is identical.

5. design an ATM

Almost all of us have used ATMs, but have you ever thought about how to design them? One of the design principles of the financial system is that it must be able to run properly under all expectations. Therefore, no matter whether it is a power failure or other violent problems, the ATM must be able to ensure the correct status. Consider locks, transaction processing, error statuses, critical conditions, and so on. Even if you are not sure about the specific design scheme, it will be helpful to point out non-functional requirements, ask some questions, or consider critical conditions.

6. If you are designing a market data class to ensure that you can switch between different information providers, such as Reuters and wombat, or directly exchange information, how do you design this market information system?

This is an interesting design interview question. In fact, it is a common problem in large investment banks. The key is that you need to provide a marketdata interface with the getbid (), getprice (), and getlevel () methods for customer requests. You also need a marketdataprovider component that uses dependency injection. This will not affect the system when you change the marketdataprovider, because the customer calls the method through the marketdata interface or class.

7. Why can't I obtain non-static variables from static methods in Java?

In Java, non-static variables cannot be obtained from static methods only because they are associated with specific object instances, but not static variables. You can also take a look at the detailed explanation in this article.

8. Use Java to design a concurrent rule pipeline?

Concurrent Programming and parallel design are very popular because it can use more and more advanced processors more efficiently, and Java is considered to be the main reason for multithreading. The key to designing a concurrent system is thread safety, immutability, and local variables, as well as avoiding the use of local variables and instance variables. You only need to ensure that multiple threads can execute the same class at the same time, so the best solution is that each thread only operates its own data and tries its best to use the smallest synchronization, especially when the MPs queue starts. This problem can be solved from the initial discussion to the compilation and implementation of final classes and interfaces, but as long as you remember to pay attention to the key issues of concurrency, such as competition status, deadlock, memory conflicts, atomic operations, threadlocal variables, and so on, try to bypass these problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.