Initial Software Architecture Experience

Source: Internet
Author: User

Over the past two months, I have struggled with architectural design. Many people may wonder how painful the architecture design is? The reason is very simple, that is, I won't! I have not systematically studied architecture design since I took office, but I have used some knowledge such as UML drawing in my work. More, I will assign tasks to me at the top, I have never designed the architecture from the beginning. I don't know where to start.

For unknown things, I started from search engines. I have been swimming on the Internet and want to find something useful to me. However, I found that I used the architecture keyword to search for many of them, including the software architecture term and some URLs. After I read the entry, I found that it is still helpful (because I have no foundation), but it seems far from enough. I want to find this tutorial and find some directories of training courses, many of which I want to learn, but I have not found any books. After trying different keywords, I found two external documents describing how to build a framework. There are too many technical terms, so I had to give up first. I found two Chinese tutorials. I started my journey of learning and practicing. The whole process is very painful, because there is no one around you to guide you, you can only rely on one or two books, you do not know whether the book is suitable for yourself, just like this, after the final completion, I felt some joy.

In fact, no matter what you do, you must know what you want to do. In our software, we need to deeply understand the requirements. This is easy to say and difficult to do. My painful experience tells me that there are too many unclear needs, and being unclear means this is not a good thing to do. Many times, customers cannot express what they want, so we need to guide them. At this time, experienced Daniel will play a very large role. There are still many functional omissions. You may not be able to remember when the customer thinks about it. The demand is uncertain, and the requirement on the architecture is very high. A Scalable architecture is a good architecture.

Find out the key features from your needs and shape your conceptual architecture around them. A teacher concluded that there are two common cases where the business process remains unchanged and the business unit is variable. The solution is to build a software framework using the design model; the other is that the business unit remains unchanged and the process changes. The solution is a service-oriented architecture that needs to adapt to the Business Process agility. I encountered the first situation.

I need a framework. In this regard, I have received strong support from my colleagues. It provides a very good framework for adapting to changes. For example, Java programming ideology introduces a Control framework, which is the same.

//: Event.java// The common methods for any control eventpackage c07.controller;abstract public class Event {  private long evtTime;  public Event(long eventTime) {    evtTime = eventTime;  }  public boolean ready() {    return System.currentTimeMillis() >= evtTime;  }  abstract public void action();  abstract public String description();} ///:~
/: Controller.java// Along with Event, the generic// framework for all control systems:package c07.controller;// This is just a way to hold Event objects.class EventSet {  private Event[] events = new Event[100];  private int index = 0;  private int next = 0;  public void add(Event e) {    if(index >= events.length)      return; // (In real life, throw exception)    events[index++] = e;  }  public Event getNext() {    boolean looped = false;    int start = next;    do {      next = (next + 1) % events.length;      // See if it has looped to the beginning:      if(start == next) looped = true;      // If it loops past start, the list       // is empty:      if((next == (start + 1) % events.length)         && looped)        return null;    } while(events[next] == null);    return events[next];  }  public void removeCurrent() {    events[next] = null;  }}public class Controller {  private EventSet es = new EventSet();  public void addEvent(Event c) { es.add(c); }  public void run() {    Event e;    while((e = es.getNext()) != null) {      if(e.ready()) {        e.action();        System.out.println(e.description());        es.removeCurrent();      }    }  }} ///:~

So how to use it? Example of a greenhouse:

//: GreenhouseControls.java// This produces a specific application of the// control system, all in a single class. Inner// classes allow you to encapsulate different// functionality for each type of event.package c07.controller;public class GreenhouseControls     extends Controller {  private boolean light = false;  private boolean water = false;  private String thermostat = "Day";  private class LightOn extends Event {    public LightOn(long eventTime) {      super(eventTime);    }    public void action() {      // Put hardware control code here to       // physically turn on the light.      light = true;    }    public String description() {      return "Light is on";    }  }  private class LightOff extends Event {    public LightOff(long eventTime) {      super(eventTime);    }    public void action() {      // Put hardware control code here to       // physically turn off the light.      light = false;    }    public String description() {      return "Light is off";    }  }  private class WaterOn extends Event {    public WaterOn(long eventTime) {      super(eventTime);    }    public void action() {      // Put hardware control code here      water = true;    }    public String description() {      return "Greenhouse water is on";    }  }  private class WaterOff extends Event {    public WaterOff(long eventTime) {      super(eventTime);    }    public void action() {      // Put hardware control code here      water = false;    }    public String description() {      return "Greenhouse water is off";    }  }  private class ThermostatNight extends Event {    public ThermostatNight(long eventTime) {      super(eventTime);    }    public void action() {      // Put hardware control code here      thermostat = "Night";    }    public String description() {      return "Thermostat on night setting";    }  }  private class ThermostatDay extends Event {    public ThermostatDay(long eventTime) {      super(eventTime);    }    public void action() {      // Put hardware control code here      thermostat = "Day";    }    public String description() {      return "Thermostat on day setting";    }  }  // An example of an action() that inserts a   // new one of itself into the event list:  private int rings;  private class Bell extends Event {    public Bell(long eventTime) {      super(eventTime);    }    public void action() {      // Ring bell every 2 seconds, rings times:      System.out.println("Bing!");      if(--rings > 0)        addEvent(new Bell(          System.currentTimeMillis() + 2000));    }    public String description() {      return "Ring bell";    }  }  private class Restart extends Event {    public Restart(long eventTime) {      super(eventTime);    }    public void action() {      long tm = System.currentTimeMillis();      // Instead of hard-wiring, you could parse      // configuration information from a text      // file here:      rings = 5;      addEvent(new ThermostatNight(tm));      addEvent(new LightOn(tm + 1000));      addEvent(new LightOff(tm + 2000));      addEvent(new WaterOn(tm + 3000));      addEvent(new WaterOff(tm + 8000));      addEvent(new Bell(tm + 9000));      addEvent(new ThermostatDay(tm + 10000));      // Can even add a Restart object!      addEvent(new Restart(tm + 20000));    }    public String description() {      return "Restarting system";    }  }  public static void main(String[] args) {    GreenhouseControls gc =       new GreenhouseControls();    long tm = System.currentTimeMillis();    gc.addEvent(gc.new Restart(tm));    gc.run();  } } ///:~

With this framework, it is easy to "separate stability and changes" and encapsulate changes.

When refining the architecture, You need to determine the interface and data structure of each module. A good data structure will greatly increase your architecture. One principle is to design the data structure so that it can adapt to changes.

At this time, you can start to define the base class, such as class diagrams and time sequence diagrams. Documentation is also essential.

In this regard, I have not done enough to start coding, and the framework is also being modified.

This is just the beginning. If you still have the opportunity to design it in the future, you will not think about this pain and embarrassment.

Related Article

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.