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

How to install .NET with dotnet-install script

Find more details in Microsoft scripted installation

  1. .NET SDK (Software Development Kit): The SDK includes everything you need to build and run .NET applications. This means it includes the runtime, but also includes other tools for developing, building, running, and testing .NET applications. This includes the .NET CLI (Command Line Interface), compilers, and libraries. You need the SDK to develop and build .NET applications.
  2. .NET Runtime: The runtime includes just the resources required to run existing .NET applications. It does not include the tools and libraries used for building applications. It's a smaller installation package compared to the SDK. When you deploy a .NET application to a server or a client machine, you usually only need to have the appropriate .NET Runtime installed on that machine, not the full SDK.

All .NET Core and .NET Versions Available for Installation via dotnet-install

Installation

$ curl -sSL https://dot.net/v1/dotnet-install.sh > dotnet-install.sh
$ chmod +x dotnet-install.sh
$ echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.zshrc
$ echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> ~/.zshrc

dotnet-install Script Reference

find reference for dotnet-install script reference in dotnet-install script reference

find options for dotnet-install script in dotnet-install script options

Continue reading

How to create and run C# project

This post is just a reminder for me. So in order to find more details about dotnet CLI, follow the below link

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet

$ dotnet new console -h

Console App (C#)
Author: Microsoft
Description: A project for creating a command-line application that can run on .NET on Windows, Linux and macOS

Usage:
  dotnet new console [options] [template options]

Options:
  -n, --name <name>       The name for the output being created. If no name is specified, the name of the output directory is used.
  -o, --output <output>   Location to place the generated output.
  --dry-run               Displays a summary of what would happen if the given command line were run if it would result in a template creation.
  --force                 Forces content to be generated even if it would change existing files.
  --no-update-check       Disables checking for the template package updates when instantiating a template.
  --project <project>     The project that should be used for context evaluation.
  -lang, --language <C#>  Specifies the template language to instantiate.
  --type <project>        Specifies the template type to instantiate.

Template options:
  -f, --framework <net5.0|net6.0|net7.0>  The target framework for the project.
                                          Type: choice
                                            net7.0  Target net7.0
                                            net6.0  Target net6.0
                                            net5.0  Target net5.0
                                          Default: net7.0
  --langVersion <langVersion>             Sets the LangVersion property in the created project file
                                          Type: text
  --no-restore                            If specified, skips the automatic restore of the project on create.
                                          Type: bool
                                          Default: false
  --use-program-main                      Whether to generate an explicit Program class and Main method instead of top-level statements.
                                          Type: bool
                                          Default: false

To see help for other template languages (F#, VB), use --language option:
   dotnet new console -h --language F#

Creating a C# Project

$ dotnet new --list

These templates matched your input: 

Template Name                                 Short Name          Language    Tags                            
--------------------------------------------  ------------------  ----------  --------------------------------
ASP.NET Core Empty                            web                 [C#],F#     Web/Empty                       
ASP.NET Core gRPC Service                     grpc                [C#]        Web/gRPC                        
ASP.NET Core Web API                          webapi              [C#],F#     Web/WebAPI                      
ASP.NET Core Web App                          webapp,razor        [C#]        Web/MVC/Razor Pages             
ASP.NET Core Web App (Model-View-Controller)  mvc                 [C#],F#     Web/MVC                         
ASP.NET Core with Angular                     angular             [C#]        Web/MVC/SPA                     
ASP.NET Core with React.js                    react               [C#]        Web/MVC/SPA                     
ASP.NET Core with React.js and Redux          reactredux          [C#]        Web/MVC/SPA                     
Blazor Server App                             blazorserver        [C#]        Web/Blazor                      
Blazor Server App Empty                       blazorserver-empty  [C#]        Web/Blazor/Empty                
Blazor WebAssembly App                        blazorwasm          [C#]        Web/Blazor/WebAssembly/PWA      
Blazor WebAssembly App Empty                  blazorwasm-empty    [C#]        Web/Blazor/WebAssembly/PWA/Empty
Class Library                                 classlib            [C#],F#,VB  Common/Library                  
Console App                                   console             [C#],F#,VB  Common/Console                  
dotnet gitignore file                         gitignore                       Config                          
Dotnet local tool manifest file               tool-manifest                   Config                          
EditorConfig file                             editorconfig                    Config                          
global.json file                              globaljson                      Config                          
MSBuild Directory.Build.props file            buildprops                      MSBuild/props                   
MSBuild Directory.Build.targets file          buildtargets                    MSBuild/props                   
MSTest Test Project                           mstest              [C#],F#,VB  Test/MSTest                     
MVC ViewImports                               viewimports         [C#]        Web/ASP.NET                     
MVC ViewStart                                 viewstart           [C#]        Web/ASP.NET                     
NuGet Config                                  nugetconfig                     Config                          
NUnit 3 Test Item                             nunit-test          [C#],F#,VB  Test/NUnit                      
NUnit 3 Test Project                          nunit               [C#],F#,VB  Test/NUnit                      
Protocol Buffer File                          proto                           Web/gRPC                        
Razor Class Library                           razorclasslib       [C#]        Web/Razor/Library               
Razor Component                               razorcomponent      [C#]        Web/ASP.NET                     
Razor Page                                    page                [C#]        Web/ASP.NET                     
Solution File                                 sln,solution                    Solution                        
Web Config                                    webconfig                       Config                          
Worker Service                                worker              [C#],F#     Common/Worker/Web               
xUnit Test Project                            xunit               [C#],F#,VB  Test/xUnit  
$ dotnet --list-sdks

5.0.408 [/Users/kenanhancer/.dotnet/sdk]
6.0.411 [/Users/kenanhancer/.dotnet/sdk]
7.0.305 [/Users/kenanhancer/.dotnet/sdk]

Creating a Console Project

Use any template short name after dotnet net and .NET SDK version after --framework option.

$ dotnet new console --framework net6.0 -o console-demo1

Creating a WebApi Project

$ dotnet new webapi --framework net6.0 -o webapi-todo-demo1

Specify .NET version in project folder

If you have multiple versions of the .NET Core SDK installed, the version that's used can be controlled using a global.json file. This file allows you to specify which version of the .NET Core SDK should be used.

$ dotnet new globaljson --sdk-version 6.0.411 --force

1. Creating a C# Console Project

-o or –output is location to place for new generated project.

$ dotnet new console --framework net6.0 --output enum_demo4

# OR

$ dotnet new console --framework net6.0 -o enum_demo4

# OR

$ dotnet new console --framework net6.0 --name enum_demo4
Folder Structure
Generated Project
Continue reading