How to resolve the algorithm Abstract type step by step in the PowerShell programming language
How to resolve the algorithm Abstract type step by step in the PowerShell programming language
Table of Contents
Problem Statement
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract types without any implementation are called interfaces. In the languages that do not support multiple inheritance (Ada, Java), classes can, nonetheless, inherit from multiple interfaces. The languages with multiple inheritance (like C++) usually make no distinction between partially implementable abstract types and interfaces. Because the abstract type's implementation is incomplete, OO languages normally prevent instantiation from them (instantiation must derived from one of their descendant classes). The term abstract datatype also may denote a type, with an implementation provided by the programmer rather than directly by the language (a built-in or an inferred type). Here the word abstract means that the implementation is abstracted away, irrelevant for the user of the type. Such implementation can and should be hidden if the language supports separation of implementation and specification. This hides complexity while allowing the implementation to change without repercussions on the usage. The corresponding software design practice is said to follow the information hiding principle. It is important not to confuse this abstractness (of implementation) with one of the abstract type. The latter is abstract in the sense that the set of its values is empty. In the sense of implementation abstracted away, all user-defined types are abstract. In some languages, like for example in Objective Caml which is strongly statically typed, it is also possible to have abstract types that are not OO related and are not an abstractness too. These are pure abstract types without any definition even in the implementation and can be used for example for the type algebra, or for some consistence of the type inference. For example in this area, an abstract type can be used as a phantom type to augment another type as its parameter. Task: show how an abstract type can be declared in the language. If the language makes a distinction between interfaces and partially implemented types illustrate both.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Abstract type step by step in the PowerShell programming language
Source code in the powershell programming language
#Requires -Version 5.0
Class Player
{
<#
Properties: Name, Team, Position and Number
#>
[string]$Name
[ValidateSet("Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers",
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings",
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans",
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers",
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets",
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins",
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers",
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks")]
[string]$Team
[ValidateSet("C","G","T","QB","RB","WR","TE","DT","DE","ILB","OLB","CB","S","K","H","LS","P","KOS","R")]
[string]$Position
[ValidateRange(0,99)]
[int]$Number
<#
Constructor: Creates a new Player object, with the specified Name, Team, Position and Number.
#>
Player([string]$Name, [string]$Team, [string]$Position, [int]$Number)
{
$this.Name = (Get-Culture).TextInfo.ToTitleCase("$Name")
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$Team")
$this.Position = $Position.ToUpper()
$this.Number = $Number
}
<#
Methods: Trade the player to a different team (optional parameters for methods in PowerShell 5 classes are not available. Boo!!)
An overloaded method is a method with the same name as another method but in a different context,
in this case with different parameters.
#>
Trade([string]$NewTeam)
{
[string[]]$league = "Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers",
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings",
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans",
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers",
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets",
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins",
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers",
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks"
if ($NewTeam -in $league | Where-Object {$_ -notmatch $this.Team})
{
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$NewTeam")
}
else
{
throw "Invalid Team"
}
}
Trade([string]$NewTeam, [int]$NewNumber)
{
[string[]]$league = "Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers",
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings",
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans",
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers",
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets",
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins",
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers",
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks"
if ($NewTeam -in $league | Where-Object {$_ -notmatch $this.Team})
{
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$NewTeam")
}
else
{
throw "Invalid Team"
}
if ($NewNumber -in 0..99)
{
$this.Number = $NewNumber
}
else
{
throw "Invalid Number"
}
}
}
$player1 = [Player]::new("sam bradford", "philadelphia eagles", "qb", 7)
$player1
$player1.Trade("minnesota vikings", 8)
$player1
$player2 = [Player]::new("demarco murray", "philadelphia eagles", "rb", 29)
$player2
$player2.Trade("tennessee titans")
$player2
You may also check:How to resolve the algorithm Quine step by step in the Lasso programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the SparForte programming language
You may also check:How to resolve the algorithm Shoelace formula for polygonal area step by step in the D programming language
You may also check:How to resolve the algorithm Padovan sequence step by step in the Go programming language
You may also check:How to resolve the algorithm Map range step by step in the NetRexx programming language