Pattern optimization object oriented software engineering


















The extrinsic state logically belongs in the flyweights, and has been extracted as an adornment. It must be passed to the concrete flyweight Character so that state can be recovered, and it must be passed to unshared concrete flyweights Row and Column , in part so that they can pass it to the Character s in turn. It is conceivable that Row s and Column s could capture a reference to the extrinsic state the GlyphContext and then they truly would not use their parameter.

However, as they mention, with this design, clients don't have to know whether they are shareable or not. This extra state would also be contrary to the flyweight design, as even the reference is not really necessary.

The flyweight pattern is an optimization, if you will, and, you can think of it is a refactoring of a simpler object-oriented design that is using too many objects.

The optimization works by separating intrinsic state from extrinsic state, with the assumption that the extrinsic state can be represented more efficiently than being replicated in each object, and, that now separated, the bulk of the remainder the intrinsic state can be shared and reused. After the refactoring, you can now invoke all the same object-oriented methods that previously existed, but the cost is that you have to pass the extrinsic state as an additional parameter now.

As an optimization, if you don't absolutely need it you shouldn't use it just because you can. It makes the code harder to use, understand, maintain, etc.. Also note that you don't necessarily have to implement unshared concrete flyweight's, it's just that you can if you need it. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more. Asked 5 years, 3 months ago. Active 4 years, 11 months ago. Viewed times. In a nutshell, a detailed description is constructed specifying how the system is to be built on concrete technologies. Object-oriented system design involves defining the context of a system followed by designing the architecture of the system. The static context of the system is designed using a simple block diagram of the whole system which is expanded into a hierarchy of subsystems.

The subsystem model is represented by UML packages. The dynamic context describes how the system interacts with its environment. It is modelled using use case diagrams. Typically, a system is partitioned into layers and each layer is decomposed to form the subsystems. Decomposition means dividing a large complex system into a hierarchy of smaller components with lesser complexities, on the principles of divide—and—conquer.

Each major component of the system is called a subsystem. Object-oriented decomposition identifies individual autonomous objects in a system and the communication among these objects. Concurrency allows more than one objects to receive events at the same time and more than one activity to be executed simultaneously. Concurrency is identified and represented in the dynamic model.

To enable concurrency, each concurrent element is assigned a separate thread of control. If the concurrency is at object level, then two concurrent objects are assigned two different threads of control. If two operations of a single object are concurrent in nature, then that object is split among different threads.

Concurrency is associated with the problems of data integrity, deadlock, and starvation. So a clear strategy needs to be made whenever concurrency is required. Besides, concurrency requires to be identified at the design stage itself, and cannot be left for implementation stage. While designing applications, some commonly accepted solutions are adopted for some categories of problems.

These are the patterns of design. A pattern can be defined as a documented set of building blocks that can be used in certain types of application development problems. During system design, the events that may occur in the objects of the system need to be identified and appropriately dealt with. The system design phase needs to address the initialization and the termination of the system as a whole as well as each subsystem. The start—up of the system, i. The termination of the system, i.

After the hierarchy of subsystems has been developed, the objects in the system are identified and their details are designed. Here, the designer details out the strategy chosen during the system design.

The emphasis shifts from application domain concepts toward computer concepts. The objects identified during analysis are etched out for implementation with an aim to minimize execution time, memory consumption, and overall cost.

These are initially compared to the assembly instructions to determine their suitability for testing, and if a match is established, the instructions are replaced. The efficiency and limitations of the optimizer appear to be mostly determined by the amount of time and space available for identifying redundant sequences of instructions.

In the above given simple code, if the store instruction is nondestructive, the third instruction is redundant and may be discarded. Lamb's Peephole Optimizers were published in The code generator generates assembly code in the form of a doubly-linked list of nodes. The optimizer uses a compiled version of the patterns, which is then simplified for testing applicability for set of instruction sequences.

The form of the optimization rules:. Condition var is optional in the above-mentioned pattern matching rule and hence expressed with square brackets ; it can only appear in the matching section of the pattern rule. In an optimization rule a condition over some variable s occurring in the pattern is referred to as an Escape by Lamb that must be met.

If all the instructions in the preconditions part can be applied to adjacent assembly code instructions with any particular conditions over variables evaluating to true then and only then the pattern match is successful.

Escapes can also be embedded, where they represent an additional action to be performed rather than describing a condition over the variables as in the matching part. McKeeman originally adopted the other approach, until more improvement can be made, one would have to go through the code several times.

Since the code has to be tested once only, the backward strategy is surely better and effective. The above discussed style of matching optimization pattern rule and backward strategy are also used by Fraser's peephole optimizer Copt through being a retargetable optimizer.

The work discussed in this article adopts the above mentioned style of pattern matching rule for the regular expression and the generic backward strategy, which is very applicable to classical peephole optimizer implementation. The classical peephole optimizers were machine dependent and so they could only specific to a single machine.

Retargetable optimizers are different then the classical ones in their capability of being machine independent and therefore easily retargeted to other machines. PO generally takes two inputs, one is assembly code of the program and the second is the target machine's descriptions on which the program suppose to be executed proceeding as follows. Ralph E. Their work provides an object-oriented framework for optimizing compilers to implement peephole optimizers.

In their work, Tanenbaum et al. In order to perform a match of a sequence of input instructions with pattern rules, the input instructions and pattern rules are stored in separate hash tables.

If the match is successful, the context sensitive information of the input is analyzed for consistency with the optimization rule. Using this way, HOP stay away from dealing with strings and enhances matching speed to that of byte-to-byte comparison.

An optimizer tool described by Whitfield and Soffa in that is basically using an optimization specification language and an optimizer generator. Ganapathi et al. For describing target machine instructions they utilize attribute grammar parsing techniques instead of using register transfers. From review of the above research works we can understand that the retargetablity and platform independency of the peephole optimizers in compiler construction had been successfully achieved but speed is always remained an issue.

In order to overcome this, the overall execution time for the code generation and optimization phases had to be reduced. As mentioned at the beginning of this section, allowing for optimization in code generation itself would have resulted in complicated case analysis.

So the goal here was to maintain the efficiency of both phases without focusing the individual algorithms too much. The concept of combining two phases of code generation and optimization in to one phase has been described by Fraser and Wendt in Using this concept they extended the initial implementation of HOP. A similar rule-based rewriting system is introduced by Ancona in The goal here was to maintain the efficiency of both phases without focusing the individual algorithms too much.

Code generation and optimization in lcc are combined into a single process, a rule based, pattern matching and replacement algorithm.



0コメント

  • 1000 / 1000