Designing SocialMediaLink in OOP

Beginning of Software Design

Requirement: Design an Actor class which has personal details and social media links.

A note on design:

The current design, with direct properties for each social media link and separate methods for updating/removing each, is more rigid and might lead to more boilerplate code as the number of social media platforms increases.

This design has some potential disadvantages:

  1. Rigidity:
    • If you wanted to add support for another social media platform, you'd have to modify the Actor class, adding a new property and accompanying methods to update and remove the link. This breaks the Open/Closed Principle (OCP) of SOLID, which states that a class should be open for extension but closed for modification.
  2. Duplication:
    • The IsValidLink method is invoked in every UpdateXXXLink method. If the validation logic changes, it will be correctly applied across all methods, but the repetitive structure is a red flag that there might be a more elegant design solution.
  3. No Single Responsibility:
    • The Actor class is currently handling both the data representation of an actor and the management and validation of links. This can be seen as a violation of the Single Responsibility Principle (SRP) of SOLID. Ideally, an Actor shouldn't have to be concerned with the intricacies of URL validation.
  4. Null State Ambiguity:
    • Using null to represent the absence of a link can lead to potential null reference exceptions if not handled properly elsewhere in the code. While setting the value to null does represent the absence of a value, it requires other parts of your application to consistently check for null before using a link.
  5. Lack of History/Tracking:
    • In the current design, there's no way to keep track of changes to an actor's social media links. If link history or auditing is a requirement (either now or in the future), this design would need to be significantly refactored.
  6. Potential for Incomplete Removals:
    • If a developer forgets to call the removal method, old data might remain in the system. In the design where links were contained in a list, you could have just cleared the list or removed specific items, ensuring all links of that type were removed.
  7. Scalability Concerns:
    • As new properties or methods are added, this class will grow, making it harder to maintain. A larger class tends to be more error-prone and harder to debug.

Recommendation:

A more flexible approach would involve encapsulating the behaviour and data of social media links into their own classes (as shown in the next designs). It allows for easier additions of new link types, centralized validation logic, and a clearer separation of concerns.

Continue reading

Notes about IP Address and Subnet Mask

Everything is working on binary number system in computers, so it is valid in IP addresses as well.

Assume that IP address is 192.168.1.0 in dotted-decimal format is equal to 11000000.10101000.00000001.00000000 in dotted-binary format.

Assume that Subnet Mask is 255.255.255.0 in dotted-decimal format is equal to 11111111.11111111.11111111.00000000 in dotted-binary format. Subnet Mask is shown in /24 in slash notation(known as CIDR notation)

IP Address with Subnet Mask can be shown in CIDR notation 192.168.1.0/24

CIDR gives a concise way to represent both an IP network and its size using a combination of an IP address and a number after a slash.

Subnet Mask is 24 after slash in decimal representation. In order to find out 24, Subnet mask should be represented in binary number system like 11111111.11111111.11111111.00000000. So, just count how many 1 bit there are in Subnet Mask.

IP Address and Subnet Mask in Decimal format:
IP Address: 192.168.1.0
Subnet Mask: 255.255.255.0

IP Address and Subnet Mask in CIDR format:
192.168.1.0/24

IP Address and Subnet Mask in Binary format:
IP Address: 11000000.10101000.00000001.00000000
Subnet Mask: 11111111.11111111.11111111.00000000

Continue reading

How to create AWS Lambda with AWS SAM CLI

According to my experience, if you want to create an AWS Lambda without interactive mode, 15 templates below don't exists for each runtime, for example, Data processing template only exists for dotnet and nodejs.

Notice that third template name is Hello World Example with Powertools for AWS Lambda in below output, but if you want to create a project with python runtime and third template in the below sam init output, you have to use hello-world-powertools-python as a template name. But it is not mentioned in help. So, i just used sam init in interactive mode and output of this command showed me template name.

sam init --name my-data-processing-app --runtime python3.9 --dependency-manager pip --app-template hello-world-powertools-python

$ sam init

You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.

Which template source would you like to use?
	1 - AWS Quick Start Templates
	2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
	1 - Hello World Example
	2 - Data processing
	3 - Hello World Example with Powertools for AWS Lambda
	4 - Multi-step workflow
	5 - Scheduled task
	6 - Standalone function
	7 - Serverless API
	8 - Infrastructure event management
	9 - Lambda Response Streaming
	10 - Serverless Connector Hello World Example
	11 - Multi-step workflow with Connectors
	12 - Full Stack
	13 - Lambda EFS example
	14 - DynamoDB Example
	15 - Machine Learning
Template: 1

Use the most popular runtime and package type? (Python and zip) [y/N]: 
Continue reading

How to create AWS Lambda, Azure Function, Google Cloud Function with Serverless Framework CLI

Serverless framework is a CLI to build cloud applications. There are more than 10 Serverless Infrastructure Providers like AWS, Azure and GCP as shown below screenshot.

Find more Serverless Framework CLI command in Azure Serverless TypeScript project in GitHub

According to my experience, Serverless Framework gives a better support for AWS provider, for example, if you see project template below, there are many project templates for AWS but very less support for other providers.

Find more details in https://www.serverless.com/framework/docs/getting-started

Continue reading