ObertShen / Lessons

BJTU Software Lessons
0 stars 0 forks source link

Advanced Software Architecture #1

Closed ObertShen closed 7 years ago

ObertShen commented 8 years ago

Repuirement:

  1. Analyze the use case of the architecture selected to identify:

    a. Bussiness driver

    b. Requirements - functional and non-functional

    c. ASRs

    d. The context, problem, and solution for the pattern of your architecture

  2. Analyze alternative applicable patterns if there is any
  3. Describe your implementation approach?
  4. Describe how would you test your system?
vincent974 commented 8 years ago

Using factories instead of constructors or prototypes allows one to use polymorphism for object creation, not only object use. Specifically, using factories provides encapsulation, and means the code is not tied to specific classes or objects, and thus the class hierarchy or prototypes can be changed or refactored without needing to change code that uses them – they abstract from the class hierarchy or prototypes. Pros: Abstraction, Polymorphism, and Loose Coupling cons: Too much abstract, Makes code more difficult to read (due to the abstraction).

ObertShen commented 8 years ago

Use case Mobile game NPC Module The role and number of characters are variables.

ObertShen commented 8 years ago

[Matertials] Business Driver: Everyone involved in the evaluation—the project representatives as well as the evaluation team members—needs to understand the context for the system and the primary business drivers motivating its development.In this step,a project decision maker(ideally the project manager or the system’s customer)presents a system overview from a business perspective.The presentation should describe the following:

ObertShen commented 8 years ago

[Materials] Business Driver : Business drivers presentation.Briefing of business drivers by project management.What are the goals of the customer organization for this system?What are the goals of the development organization?This is normally a lengthy discussion that allows participants to ask questions about the business goals as presented by project management. Other References

ObertShen commented 8 years ago

[Output] Functional requirements : One or two players; Many kinds of NPC, every NPC has different of AI, attributes, skills. Non-functional requirements : The module should be measurable, scalability of game evolution, testable.

ObertShen commented 8 years ago

[Output] Edited by Lee: After search a lot of materials and ask some people,we can’t found any other pattern could replace the factory pattern in design of games. We discover most of games are developed to use factory design pattern. Such as our example ,when we want to create a new npc we don’t need to create a new class for him,we just need to add new factory and new subclass to implement the master class. So is a very efficient way to complete our project. Advantage: Define an interface for creating an object,but let subclasses decide which class to instantiate.Factory Method lets a class defer instantiation to subclasses. abstraction, polymorphism, and loose coupling So factory design pattern is unique way for our use case.

ObertShen commented 8 years ago

[Output] Business drivers : A project spokesperson describes what business goals are motivating the development effort and hence what will be the primary architectural drivers (e.g., high availability or time to market or high security).

ObertShen commented 8 years ago

[Output] ASRs : First is availability, another is efficiency.

ObertShen commented 8 years ago

[OutPut] Edited by lee Implements:


public interface Character {
    void do(); // Exposed method
}

public abstract class AbstractCharacter implements Character {

}

public class Player1 extends AbstractCharacter {
    private String name;
    public play1(String name){ 
        this.name = name;
    }
    @Override
    public void do() {
      // ...
    }
}

public class NPC1 extends AbstractCharacter {
    private String name;
    public npc1(String name){ 
        this.name = name;
    }
    @Override
    public void do() {
        // ... 
    }
}

public interface CharacterFactory {
    Character getCharacter();
}

public class Player1Factory implements CharacterFactory {
    @Override
    public Character getCharacter() {
        return new Player1(Player1.class.getName());
    }
}

public class NPC1Factory implements CharacterFactory {
    @Override
    public Character getCharacter() {
        return new NPC1(NPC1.class.getName());
    }
}