Application Design

Elements of Application Design – Key Considerations

•Availability and Reliability
–Availability
•A system's accessibility during daily operations, or the ability of a system to perform its functions at any given instant under certain conditions.
–Reliability
•The average length of time an application runs without failure.  It is also about providing the expected results, consistently, without unexpected surprises, failures or errors.
•Performance
–The response time of the system for a user request.

优化jdbc例
大数据量的时候,PreparedStatement+batch
PreparedStatement stmt = conn.prepareStatement("INSERT INTO Userinfo(username,password) VALUES(?,?)");
User[ ] users = addUser();//取得 要插入的数据的数组
for(int i=0; i<users.length;i++){
stmt.setString(1, users[i].getUsername());
stmt.setString(2, users[i].getPassword());
stmt.addBatch( );
}
int[ ] counts = stmt.executeBatch();


 
•Scalability
–Attribute of a software system that characterizes the degree to which an application can support an increase in processing volume or in number of users.
•Maintainability
–The ability to perform preventive and remedial maintenance activities on the infrastructure.
 
•Security
–The ability of the system to resist unauthorized attempts to access the system and denial-of-service attacks while still providing services to authorized users.
•Operability
–The ability of an architecture to allow routine support activities (for example, backups, event monitoring, batch scheduling) to be undertaken without any disruption to the live service.

•Deliverables from the Analysis and Design Phases:
–Class Diagram
–Created in the Analysis Phase to provide an overview of the classes identified and their relationships. Updated in the Design Phase to reflect any new classes and relationships found.
Defining class specifications involves:
Defining class visibility
Defining operations
Defining attributes
Representing relationships

class Diagram
Interaction Diagrams, ex:–Sequence Diagrams (focus on order of interaction)

sequence Diagram
–State Diagrams

state chart
–Activity Diagrams
–Class Definition
–Component Diagram

•Design Principles include:
–Open Close Principle (OCP)
–Dependency Inversion Principle (DIP)
–Liskov Substitution Principle (LSP)
–Single Responsibility Principle (SRP)
–Interface Segregation Principle (ISP)
–Law of Demeter (LoD), or Principle of Least Knowledge
 
•Characteristics of Design Patterns:
–Reusable solutions to recurring problems.
–Distilled from the experiences of experts.
–Repeats a successful design done by someone else.
–Provides us with a vocabulary to describe and discuss a particular design.
–Designers can recognise a problem to which specific patterns apply and immediately determine the solution without having to stop to analyse the problem first.
 
•Guidelines while using Design Patterns:
–Do not try throwing patterns into design.
–Do not try to use all the patterns.
–Keep the design simple and do not add unnecessary levels of indirection.

•Key considerations in class design:
1State Management: This is the mechanism used to maintain state of an object.
2Data validation: Ensures that data is validated prior to applying business rules and/or persisted in the repository.
3Exception handling: A mechanism for dealing with errors and failures of the application.
4Transaction management: Coordinates transactions across one or more resource managers within a network, and ensures that all resources for a transaction are updated, or in the case of an update failure on any one resource, all updates are rolled back.
5Logging and Audit Tracing Services: Permanently store application information in a data store that can be later accessed for operations management.
6Multi-Threading and Thread Safety:
Multi-threading enables different parts of a program to be executed by different threads.
Thread safety means that the code functions properly when executed simultaneously by multiple threads.
7Marshalling and Serialization:
Marshalling: The process of breaking the object into a form that can be sent over the network.
Serialization: The process of breaking the object into a sequence of bytes.
8Security: Security Services play a vital role in applications and are a part of a majority of application requirements.

1 State Management
Categorize classes into stateful and stateless.
Business classes, service classes, and data store classes are generally stateless.
Decide how the state information is to be maintained
Memory
Database
Objects on disk
Java Persistence API
Hibernate
2Data Validation
Data validation takes place in the following places:
Client Browser
Presentation Layer
Business Layer
Data Access Layer
There are two types of validation that can be performed on data provided by the user:
Shallow validation is a simple algorithmic validation or data validation that can be performed without reference to large business data sets.
Examples of shallow validation include:
Checking that mandatory data fields do not contain null or empty values.
Range checking for minimum and maximum values.
Checking the format of data such as postcodes, sort codes, etc.
Simple algorithmic checks. An example of a simple algorithmic calculation would be the determination of whether a particular day is a working day. Determining non-weekend days is easy using modulus maths from a seed date, but public holidays are more easily determined using a small dataset containing the public holidays for a given year. Eight public holiday dates for each year would be an example of a small dataset if the validation is not done over too long a timeframe!
The designer must determine which shallow validation needs to be performed in the UI and decide whether it should be client-side or server-side or both. Shallow validation is typically done in the UI layer, before the data is passed to the business layer. Validations may be duplicated in the business layer depending on where the same data is passed to the business layer apart from the UI layer.
Deep validation is a more complex algorithmic validation or data validation that requires large business data sets to successfully complete the validation. An example of deep validation is ensuring that a number such as “99999” represents a real zip code rather than just looking like one.
Guideline:
During design, keep track of all validations to be done as well as the layer/component in which they would need to be taken care of.
In summary, apart from validating user input in the UI layer, validations are also done in the business layer. These are typically business validations. Different methods may be used for validating data, such as having rules engines or utility classes, or having them in the business components.
3Exception Handling
Exception: A mechanism for dealing with errors
Causes of exceptions:
Programming errors
Resource failures
Functional errors
Interface/Third Party errors
Exception handling:
Restores an application to a known state
Takes appropriate corrective action
Guidelines for exception handling
4Transaction Management
Transaction Management involves:
Coordinating transactions
Ensuring all resources involved in a transaction are updated
Ensuring all updates are rolled back in case of failure
Transactions are typically initiated at the business layer as they may span multiple resources and/or entities.
5Multithreading and Thread Safety
Multi-Threading: Allowing different parts of a program to be executed by different threads.
Benefits
Improves responsiveness
Improves throughput
Disadvantages
Deadlocks
Race Conditions
Shared resources: Operations must access one-at-a-time.
Sequence of operation: Operations may be required to access a shared resource in a particular order.
6Logging and Audit Tracing
Logging and audit tracing services permanently store application information in a data store that can be later accessed for operations management.
Typically, logging and audit tracing services are used to:
Keep track of technical failures.
Monitor the load of a server or the use of an application.
Document the use of sensitive application or system privileges, such as creating new users.
Store transaction and digital signature data for non-repudiation purposes.
Design Decisions
Know the logging and audit tracing requirements of the system
Understand their later usage
Select an approach to implement logging or audit tracing mechanism
Concerns
Decisions regarding the log
File size and its maintenance
Archival frequency
Guidelines
Record application specific messages
Actively monitor and fix errors in logs
Optimize logging settings
Keep file size manageable
7Marshalling and Serialization
Scenarios for marshalling/serialization
Transferring an object over the network in distributed environments.
State maintenance, by storing the sequence of bytes in a file or database
8 Security
Application security includes the following components:
Authentication: Verifying that someone is who they claim they are.
Authorization: Finding out if the person, once authenticated, is permitted to have the resource.
Access Control: Controlling access to a web resource.
Encryption: Providing confidentiality of information, both while in transit and in storage


Elements of Application Design – Architecture Layers

Presentation Layer
UI Layer
UI Controller
Business Logic Layer
Data Access Layer


The main responsibility of a data access layer is to insulate the business logic layer from the technical specifics of how the information is stored and accessed.
The data access layer typically does the following:
Maps data between the business data structure to the physical data structure.
Manages input/output (I/O) operations with the data store.
Makes any data-type conversions as needed depending on the data store being used.
Handles data access/retrieval-related errors.
The data access layer should contain a minimum amount of processing logic (nothing more than the functions listed on this page).  

Key considerations used in creation of page specifications:
Data binding
Validation
State Management
Data propagation across screens
Exception handling
Localization and Internationalization
Security
Caching
Browser dependency

优化jdbc例
大数据量的时候,PreparedStatement+batch
PreparedStatement stmt = conn.prepareStatement("INSERT INTO Userinfo(username,password) VALUES(?,?)");
User[ ] users = addUser();//取得 要插入的数据的数组
for(int i=0; i<users.length;i++){
stmt.setString(1, users[i].getUsername());
stmt.setString(2, users[i].getPassword());
stmt.addBatch( );
}
int[ ] counts = stmt.executeBatch();

猜你喜欢

转载自sayler.iteye.com/blog/558927