Object-Oriented Analysis Design (OOAD) and UML Cheatsheet
Object-Oriented Analysis Design (OOAD) and UML Cheatsheet
1. Abstraction
Definition: Simplifying complex reality by modeling classes based on essential
properties and behaviors
2. Encapsulation np.dot(inputs)⇒outputs
Definition: Hiding internal state and requiring all interaction to occur through
an object's methods
3. Inheritance
Definition: Mechanism where a class inherits properties and methods from a
parent class
4. Polymorphism
Types:
classes
OOAD Process
Techniques:
Requirement gathering
Domain modeling
Techniques:
Design patterns
SOLID principles
Implementing methods
Testing objects
SOLID Principles
1. Single Responsibility Principle (SRP)
Software entities should be open for extension but closed for modification
UML Diagrams
Structural Diagrams
1. Class Diagram
Purpose: Shows system's classes, attributes, methods, and relationships
Key Elements:
Relationship Notations:
Multiplicity Notations:
1: Exactly one
n: Exactly n
n..m: From n to m
2. Object Diagram
Purpose: Shows instances of classes at a specific point in time
3. Component Diagram
Purpose: Shows how components are wired together to form larger
components or software systems
4. Package Diagram
Purpose: Shows how elements are grouped into packages and dependencies
between packages
5. Deployment Diagram
Purpose: Shows hardware configuration and software artifacts deployed on
that hardware
Behavioral Diagrams
Key Elements:
2. Sequence Diagram
Purpose: Shows object interactions arranged in time sequence
Key Elements:
3. Activity Diagram
Purpose: Shows flow of control from activity to activity
Key Elements:
Transitions (arrows)
Fork/join (bars)
┌─────────┐
│ Start │
└────┬────┘
│
▼
┌─────────────────┐
│Enter Credentials│
└────────┬────────┘
│
▼
◇───────◇
╱ ╲
╱ Valid? ╲
╱ ╲
│ No │
│ │
▼ ▼
┌──────┐ ┌───────────┐
Key Elements:
┌───────┐
───> │Idle │
└───┬───┘
│cardInserted
▼
┌───────┐ invalidPIN
│Validate│<────────┐
└───┬───┘ │
│ │
│validPIN │
▼ │
┌───────┐ │
│Active │──────────┘
└───┬───┘
│logOut/cardEjected
▼
┌───────┐
│ Final │
└───────┘
5. Communication Diagram
UML Relationships
1. Association
Represents a relationship between classes
2. Inheritance (Generalization)
"is-a" relationship
3. Aggregation
"has-a" relationship (whole-part)
4. Composition
Stronger form of aggregation
6. Realization
Class implements an interface
Structural Patterns
Adapter: Allows incompatible interfaces to work together
Behavioral Patterns
Observer: Notifies dependents when object changes
2. Domain Analysis
Identify key concepts in the problem domain
3. Interaction Analysis
Define how objects interact
4. Detailed Design
Refine class diagrams with attributes and operations
5. Implementation Planning
Map design to implementation language
UML Tools
Enterprise Architect - Comprehensive modeling tool
Best Practices
Analysis Phase
Focus on what, not how
Design Phase
Apply SOLID principles
UML Modeling
Use consistent notation
from flask import Flask, render_template, request, redirect, url_for, session, fla
sh
Routing
# Basic route
@app.route('/path')
def path_handler():
return 'This is a path'
Templates
@app.route('/template')
def template_example():
return render_template('example.html', title='Flask', message='Hello!')
Request Handling
@app.route('/form', methods=['POST'])
def handle_form():
username = request.form.get('username')
password = request.form.get('password')
# Get files
if 'file' in request.files:
file = request.files['file']
file.save('/path/to/save/' + file.filename)
@app.route('/error')
def error_example():
return render_template('error.html'), 404# Set status code
@app.route('/session')
def session_example():
session['username'] = 'user123'# Set session variable
user = session.get('username')# Get session variable
session.pop('username', None)# Delete session variable
# Set cookies
resp = make_response(render_template('index.html'))
resp.set_cookie('user_id', '12345')
# Get cookies
user_id = request.cookies.get('user_id')
return resp
Flask Blueprints
@admin.route('/')
def admin_index():
return render_template('admin/index.html')
# In main app.py
from blueprints.admin import admin
app.register_blueprint(admin)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)
# Define a model
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
def __repr__(self):
return f'<User {self.username}>'
# CRUD operations
@app.route('/create_user')
def create_user():
new_user = User(username='john', email='john@example.com')
db.session.add(new_user)
db.session.commit()
return 'User created!'
@app.route('/get_users')
def get_users():
users = User.query.all()
user = User.query.filter_by(username='john').first()
return str(users)
@app.route('/update_user/<int:id>')
def update_user(id):
user = User.query.get(id)
user.username = 'updated_name'
db.session.commit()
return 'User updated!'
@app.route('/delete_user/<int:id>')
def delete_user(id):
user = User.query.get(id)
db.session.delete(user)
db.session.commit()
return 'User deleted!'
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
@app.route('/logout')
def logout():
logout_user()
return redirect(url_for('index'))
@app.route('/protected')
@login_required
def protected():
return f'Hello, {current_user.username}!'
Deployment Configuration
Flask Extensions
class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
submit = SubmitField('Log In')
class UserResource(Resource):
def get(self, user_id):
user = User.query.get(user_id)
return {'username': user.username}