It has always been a good question to ask: “How to trace the design of a program?”, The most obvious answer is to trace the design patterns. Finding design patterns in source code is hard, so researchers are trying to find simpler patterns to trace. The main idea of this blog post is to define “Micro Patterns” which are one-class design patterns, and talk about their importance and how they are related to SAPM. Micro Patterns are midway between simple structures and design patterns! Let’s see 🙂
2. Patterns! Patterns! Patterns!
In the SAPM course we had a lecture about “Design Patterns” and another about higher-level patterns called “Architectural Patterns” followed by another lecture about an important example of Architectural Patterns which is Scripting Components. I have also seen that there are many blog posts my colleagues posted about these patterns!
2.1. Hey! Do you remember what design and architectural patterns are?
RECAP: Design Patterns are approaches and solutions for problems occurring repeatedly in object-oriented software development . They provide a shared vocabulary and ease the communication between developers. Design patterns are template solutions  that might contain one class (such as Singleton) or ,most-of-the-time more than one class (2,3..or more). Architectural Patterns care about the whole project, not specifically to a problem. The aim is to build reusable components .
2.2. Allan, SPAM and the big step!
I want to go back to SAPM lectures. Allan stated that developers solved the idea of reusability in small but not in large-scale projects. Just go back to the first slides of the Design Patterns lecture  and check how we started from finding simple patterns in codes (e.g. how developers patterned the looping idea as a “for” structure). I felt that there is a dramatically big step from finding simple patterns that led to defining structures like (loops, methods, classes,…etc) to finding higher-level patterns like the design patterns. Don’t you think the same?
This idea reminds me of a paper I once read and it talked about what they called “Micro Patterns”!
2.3. Ok? So isn’t it enough we have all these types of patterns! You want us to have more?!!
Simply… YES!!!! Most of design patterns contain more than one class and it is really HARD to find patterns in more than one class. My research review last semester was about finding patterns in source code and i found that it is difficult to find patterns in one class so how about finding patterns among several classes?
Simply, I think we should work to find some simple patterns and then work to find some more sophisticated patterns. I am not saying that we CAN’T find these complex patterns immediately. Some people have already done so but as Mak, Choy and Lun said, “. . . automation support to the utilization of design patterns is still very limited”.
3. Finding Patterns in Source Code! What is this?
Finding patterns in source code means searching for interesting information and structures in the code. The aim is to detect similar code fragments in source code. Finding these patterns has many applications such as bugs detection, code quality determination , and refactoring. Although the machine learning (ML) techniques and natural language processing (NLP) algorithms are mostly developed by researchers in the field of computer science and artificial intelligence, they are not used that much to solve the problems of informatics itself. Using the ML and NLP techniques to find patterns in source code seems an interesting field as it seeks to solve the problems of informatics by using tools developed by people from the same field.
3.1. ok! But What are Micro Patterns?
As stated in the introduction, It has always been a good question to ask: “How to trace the design of a program?”, The most obvious answer is to trace the design patterns. Many systems do this but with low precision and high error rate. Some researchers suggested looking for other patterns which are traceable and less abstract [6, 7]. The term “Micro Patterns” is used to represent the class-level traceable patterns. Finding these patterns has a great influence on Software engineering as they might help in using more efficient design, code reuse, and automation.
Finding patterns in a source code is extremely useful, but can you use these techniques to generate new patterns? Answering this question is somehow hard as we need new ways to let our algorithms understand the object oriented programming fundamentals such as the inheritance and polymorphism.
3.2. Wait a little, I googled “Micro Patterns” and didn’t find much results!
Well, I did too! While some people consider these patterns as a kind of design patterns since they aim to create a sharable vocabulary in addition to the previous advantages, the term is mostly used by people working in the field of source code mining to refer to one-class patterns they want to find!
Well, I think, and as stated in SAPM lectures, reusability in small projects is solved by defining structures but we still need to formalize the solutions for higher-level larger-scale projects. Micro Patterns are somewhere in the middle between simple structures and higher-structures. Searching for them and using them will have lots of advantages.
Micro Patterns are one-class design patterns that are easier to find and therefore to be formalized. They have the advantages of design patterns as they are types of them beside the benefit that they are easier to find.
Note: I didn’t want to fill the blog post with names and descriptions of micro patterns since my aim was to introduce the Micro Patterns without drowning in their details. People interested in getting more details about the topic are recommended to read the paper “Micro patterns in Java code”.
 Jeffrey K. H. Mak, Clifford S. T. Choy, and Daniel P. K. Lun. Precise modeling of design
patterns in UML. In Proc. of the Twenty Sixth International Conference on Software Engineering
(ICSE’04), pages 252–261, Edinburgh, Scotland, United Kingdom, May 23-28
2004. IEEE Computer Society Press.
 Balanyi, Zsolt and Ferenc, Rudolf, Mining design patterns from C++ source code, International Conference on Software Maintenance, ICSM, pages=305-314, IEEE, 2003.
 Gil, Joseph Yossi and Maman, Itay, Micro patterns in Java code, ACM SIGPLAN Notices, Volume 40, Number 10, pages 97-116, ACM, 2005.