In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what pair programming refers to in ThoughtWorks. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Rumor: in China, ThoughtWorks is called "the most difficult IT company to interview". It seems that it has also been rated as the most difficult IT company in the world to interview abroad.
Interviews are generally on paper, especially the interview questions that need to be "put into practice" such as design patterns. The interviewer is given "homework" before the interview, and then Thoughtworks will send engineers and interviewees to pair programming, allowing the interviewer to demonstrate his or her programming specification, design, and refactoring capabilities through test-driven and code refactoring. At this time, it is easy to see the interviewer's mastery and application of the design pattern.
Design patterns can generally be mentioned in the interview process. But this really depends on the mood of the interviewer. Ask simply, singleton mode, factory model, and then a little deeper, how the single-interest model ensures the realization of the singleton, it feels a little picky.
What is the difference between callback function and observer mode?
As a "senior programmer", you must be thinking about this problem very quickly when you see this topic. In fact, this topic is not a key test of your design pattern ability, but a test of a programmer's ability to respond in time.
Observer mode
The definition of the observer model is easy to find online:
The observer pattern defines an one-to-many dependency between objects, so that whenever an object changes its state, all objects that depend on it are notified and updated automatically.
Observer mode is widely used in Android. You may have used ListView's adapter.notifyDataSetChanged to trigger ListView's list interface for updates. The internal implementation of notifyDataSetChanged is based on the observer pattern.
Follow this code and you will find that the DataSetObserver implementation in BaseAdapter
Observer interface, DataSetObservable (the observed) inherits the Observable class.
The standard observer pattern should be written according to the following UML diagram:
There are several concepts (abstract topic (Subject), concrete topic (ConcreteSubject), abstract observer (Observer), and concrete observer (ConcreteObserver)). Fortunately, Java helps me implement the relevant code, and the observer pattern can be implemented through Observable classes and Observer interfaces. The Observer object is the observer and the Observable object is the observed.
EventBus, RxJava and other common open source libraries are also designed in observer mode, but they are implemented in different ways.
Callback function
What does the callback function have to do with this? Look at this all-too-familiar code snippet:
View's Listener snooping passes a Listener object to View through setOnClickListener, which triggers onClick (callback onClick) when a related event occurs. This is actually an observer mode. OnClickListener is the observer and View is the observer. When View receives a Click event, it notifies the observer to execute onClick ().
Reflection on Design pattern
The external form of the model is actually "routines", which come from the summary of real production practice, but be aware that not all "routines" will be suitable for you.
Design patterns are a set of repeatedly used, well-known, classified and cataloged summaries of code design experience. Design patterns are used to reuse code, make it easier for others to understand, and ensure code reliability.
The original intention of the design pattern is to use tested "routines" to improve the productivity of the code, and it is easy for people to understand the conventional "routines". From the point of view of object-oriented design, it is actually to achieve high cohesion and low coupling.
So, when considering what kind of pattern or combination of patterns to use, we might as well calm down and recall the SOLID principles of object-oriented design. We should follow certain principles, not patterns for the sake of patterns.
SOLID principles of object-oriented design:
S single function principle: objects should have only one single function.
O opening and closing principle: the software body should be open for extension, but closed for modification.
L-Richter substitution principle: objects in a program should be replaceable by its subclasses without changing the correctness of the program.
I interface isolation principle: multiple specific client interfaces are better than one wide-purpose interface.
D dependency inversion principle: depends on abstraction rather than an instance, and dependency injection is an implementation of this principle.
So to sum up: (the answer is not a standard, but a way of thinking)
The observer pattern defines an one-to-many dependency that allows multiple observer objects to listen to a subject object at the same time. The observer pattern perfectly separates the observer from the observed object. When the state of an object changes, all objects that depend on it are notified and refreshed automatically.
In fact, the callback function is also a way to implement the observer pattern, and the observer and the observed of the callback function are often one-to-one dependencies.
So the most obvious difference is that the observer pattern is a design idea, while the callback function is a specific implementation; another obvious difference is the one-to-many or many-to-many dependency.
What are the design patterns commonly used in Android?
Standard answer:
Adapter mode: GridView, Adapter of ListView
Builder mode: AlertDialog.Builder
Observer mode: ListView's adapter.notifyDataSetChanged
Chain of responsibility Model: event Distribution of View
On the ThoughtWorks pair programming refers to what is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.