Software

Abstract Data Types and Object-Oriented (basics)

Each programming paradigm has its own set of constructs and their use will shape the system you create.

The main OO concepts:

  1. Abstraction – simplify a concept by ignoring unimportant details.
  2. Encapsulation – allows to bundle data and functions into a self-contained object, so the other objects can interact with it through an exposed interface.
  3. Decomposition – allows you to break up a whole problem into smaller, distinct parts.
  4. Generalization – allows you to factor out conceptual commonalities.

Object-oriented refers to a system composed of objects. where each object is an instance of a class (the type of each object is its class). Objects may interact with each other through the use of their methods. The OO paradigm allows for inheritance among abstract data types (one abstract type can be declared an extension of another type).

Architecture · Software

UML Activity Diagram

In a UML activity diagram, you represent the control flow from one activity to another in software system (like a levels in video game). You can consider activities as actions that further the flow of execution in a system. They are actions, that when completed, cause another action to execute. For example these actions can alter objects or create new objects. These changes/actions drive the application forward.

The purpose of the activity diagram is to capture the dynamic behaviour of the system. The activity diagram allows you to map out the branching into alternative flows.

When creating the diagram, firstly have to identify the activities.

Activity diagram have 2 major parts, the start and end nodes:

Start and End nodes.png
The start and end nodes

The intermediate activities are shaped as a pill. They describe all of the activities that change the game state before the game ends.

Intermediate Activity.png
The intermediate activity
Continue reading “UML Activity Diagram”
Architecture · Software

UML Deployment Diagram

Software release involves:

  • Separate libraries
  • An executable.
  • An installer.
  • Configuration files.
  • Other different pieces.

To make software ready to run, need an idea of how to fully deploy all the different files to a needed environment. To visualize it, can use the UML deployment diagram. The deployment environment (deployment target) can be very specific. The details on the deployment diagram will change accordingly.

The physical result of the development process is artifact. For example artifacts for video game can include an executable, installer, audio libraries, multimedia assets.

An artifact.png
An Executable artifact.

There are 2 types of deployment diagrams:

Continue reading “UML Deployment Diagram”
Architecture · Software

UML Package Diagram

A package – groups together elements of a software that are related. This elements can be related based on Data, Classes, User Tasks.

A package also defines a namespace for the elements it contains, helps to organize the named elements of a software into a separate score. An element can be uniquely identified in the system by a fully qualified name, based on the own name and the name of the package that element is in (namespace).

Package diagram show packages and the dependencies between them. The packageable elements might be: Data, Classes, Other packages. Package diagrams are helpful for when you want a high-level look at your system, how different packages depend on each other.

A package has a simple depiction, which looks like a tabbed folder.

Package.png
A package without details.
Package with details.png
A package with details.
Continue reading “UML Package Diagram”
Software

UML Component Diagram

UML component diagrams are concerned with the components of a system. Components are defined as independent, encapsulated units of the system. Each component provides an interface for other components to interact with it.

Component Diagram.png
The Component Diagram example.

The Component Diagram are used to visualize how a system’s pieces interact and and what relationships they have among them. This is high-level diagram, and shouldn’t considered to have details.

Continue reading “UML Component Diagram”
Software

“4+1” Model View

It’s a difficult to capture the complete behavior of a system with a single perspective. Hence we have to observe it from 4 views.

1 – Logical View

Focuses on the functionality of a system and the objects found within it. The context is the services that should be provided to the end users. From the found objects you can create a UML class diagram that illustrates the logical view.

The class diagram has several purposes such as establishing the vocabulary of the problem and resulting system by defining all of the classes, their attributes and behaviors. It becomes easy to understand the key abstraction and terminology. The Logical View is also useful when specifying database schemes.

2 – Process View

It presents the processes implemented by the objects in the logical view. Focusing on non functional requirements which specify the desired qualities for the system. It includes quality attributes such as Performance and Availability.

Also helps to show the execution order of your different objects. It would show the calls to methods by the logical view in the correct order. Behaviors that asynchronous or concurrent are also described.

A UML sequence diagram would be helpful for illustrating the methods.

A UML activity diagram can illustrate the processes or activities for a system.

Continue reading ““4+1” Model View”
Software

Code Smells (Anti-Patterns)

  1. Comments – public methods should have comments. In the same time too many comments is bad and means that the code is unreadable without the comments. The code should be clean enough to avoid comments inside of the methods. Also, you should to avoid the comments which saying “if you update this, then update the next…”.
  2. Duplicated code – is when you have blocks of code that are similar but with slight differences. These blocks appear in multiply places of the system.
  3. Long method – self explained, you don’t want to have long methods. Having a long method can sometimes indicate that there is more occurring in that method than should be. Or it’s more complex than it needs to be.
  4. Large class – its referencing the “God classes”/”Black hole classes” which are getting bigger and bigger. They normally start as a regular size class. But as more responsibilities are needed, these classes seems like the appropriate place to put the responsibilities. But as it going to have more responsibilities, then it tend to attract more responsibilities, hence the class going to be larger and larger and keeps attract more and more responsibilities. To avoid this, you need to be explicit about the purpose of the class and keep the class cohesive, so it does one thing well.
Continue reading “Code Smells (Anti-Patterns)”
Software

Composing Objects Principle

The principle states that classes should achieve code reuse through aggregation rather than inheritance. For example the Composite design pattern and the Decorator design pattern use this approach.

The idea here that concrete classes can delegate tasks for other concrete classes. Delegation will provide loser level coupling then inheritance. Hence, provide your system more flexibility.

Disadvantages of Composition:

The biggest drawback of composition is that you must provide implementations for all behavior without the benefit of inheritance to share code. This means that you might have very similar implementations across the classes.

Software

Least Knowledge Principle

To manage complexity, one idea is that a class should be designed so that it does not need to know about and depend upon almost every other class in the system. By limiting which classes communicate with each other, you can enforce the principle of Least Knowledge. This principle is also realized in a rule known as The Law of Demeter.

The underlying idea of this Law is that classes should know about and interact with as few other classes as possible. This means that any class should only communicate with its “immediate friends”. These “friends” would be other classes that one class should only know about. It helps to reduce coupling and provide stability to a system.

  • A method, M, is an object, O, can call on any other method within O itself (encapsulated within the same object).
  • A method M, can call the methods of any parameter P (encapsulated within an object that is in the parameters of M).
  • A method M, can call a method, N, of an object, I, if I is instantiated within M (encapsulated within an object that is instantiated inside of M).
  • Any method, M, in object O, can invoke methods of any type of object that is a direct component of O (encapsulated within an object that is referenced in an instance variable of the class for M).

To summarize the rules, a method should not invoke methods of any object that is not local.

Classes should know as little as possible about your system as a whole, this will help to reduce amount of coupling and prevent unwanted effects from cascading through your entire system.

Software

SOLID (I) – Interface Segregation Principle

The Interface Segregation principle states that a class should not be forced to depend on methods it does not use. This means that any classes that implement an interface, should not have “dummy” implementations of any methods defined in the interface. Instead, you should split large interfaces into smaller generalizations.

The example before applying the Interface Segregation principle:

Not Applied Interface Segregation Principle Class Diagram.png
Not applied Interface Segregation principle

The best way is to apply Interface Segregation principle applying splitting the ICashier interface into 2 smaller. This will allow each interface to be more accurate with its description of expected behaviors, and it will allow you to pick and choose which correct combinations of interfaces a concrete class should implement.

Continue reading “SOLID (I) – Interface Segregation Principle”