Evolutionary architecture and emergent design: language, expression and design

Source: Internet
Author: User
Tags expression modifier modifiers

Introduction: The ability to discover and accumulate idiomatic patterns is critical for emergent design. It is also very important for design to be the expression of the code. In the 2nd installment of this series, Neal Ford will continue to discuss the intersection of expression and pattern, illustrating these concepts through idiomatic patterns and formal design patterns. He reconstructed some classic four-person (Gang of Four) patterns for the JVM using dynamic language to illustrate how the more expressive language allows you to see the design elements that are obscured by the opacity of the language.

This article is part 2nd of this series, designed to demonstrate the importance of computer language expression (allowing you to focus on nature, not form) for emergent design. The divergence between intent (intent) and results (result) is a common problem for many older languages (including the Java™ language), thus adding unnecessary forms to the issue-solving effort. More expressive languages can help developers find idiomatic patterns more easily because they contain less useless information. Expressiveness is a feature of modern languages such as Groovy and Scala; the older but more expressive languages include Ruby (where JRuby is a variant of the JVM), and other, more expressive languages include refurbished Clojure and modern Lisp based on the JVM. In this article, I'll go on to the demo in part 1th-using the traditional four-person group pattern in the book of design patterns in a more expressive language.

Modifier pattern

A four-person group of books defines a modifier pattern as:

Assign additional responsibilities dynamically to an object. Modifiers provide another flexible inheritance method for extending functionality.

If you have ever used a java.io.* package, you should know something about the modifier pattern. Clearly, the designers of I/O libraries read the modifiers section of the four-person book and understood its core meaning! First, I'll demonstrate the traditional implementation of the modifier pattern in Groovy, and then improve its dynamics in subsequent examples.

Traditional modifiers

Listing 1 shows a Logger class, along with some modifiers (Timestampinglogger and Upperlogger) associated with the class, that all code is implemented in Groovy:

Listing 1. Logger and two modifiers

class Logger {
  def log(String message) {
     println message
  }
}

class TimeStampingLogger extends Logger  {
  private Logger logger

  TimeStampingLogger(logger) {
     this.logger = logger
  }

  def log(String message) {
     def now = Calendar.instance
    logger.log("$now.time: $message")
  }
}

class UpperLogger extends Logger {
  private Logger  logger

  UpperLogger(logger) {
    this.logger = logger
  }

  def log(String message) {
    logger.log(message.toUpperCase())
  }
}

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.