Here's how watches work: there's a spring with tension which is unwound in a regulated way, using a balance wheel. The balance wheel serves the same purpose as a pendulum in a pendulum clock.
My watch will have a second hand, a minute hand, an hour hand, and a day hand (a.m. v. p.m.)
I'm not going to follow my odometer design – which used the value of one wheel to drive another wheel. All the wheels on this watch will be driven off the same spring, progressing at different rates.
OK, I'm probably going to need two classes: a hand class for each of the displays and a spring class that drives the watch. Here's the division that jumps out at me:
Hand:
- Constructor for the different types of hands
- State for the hand
- Methods for changing the state
- Method for displaying or polling the state.
Spring:
- Constructor that registers hands with the spring
- Tick method that moves all the hands forward.
- Wind method that tightens the spring
- Set methods to set the value of the hands
- Display method to show the time.
- A main method, such that this project could be compiled as a stand-alone console app.
I'd like to set up some kind of a handshake between the two classes such that a tick is verified as having succeeded.
OK, time to start putting together the infrastructure:
- Create a new folder, called watch, for this stuff to live in.
- Create subfolders: Test, Code, Backup, Docs.
Actually, instead of just doing this, I'm going to capture this in a function. After some playing around, here's what I came up with:
function newProject ($rootdir, $newDir){
pushd $rootdir
mkdir $newDir
cd $newDir
mkdir "Test"
mkdir “Code”
mkdir “Backup”
mkdir “Docs”
popd
}
OK, now I need to populate this with stubs.
Wait, wait, wait – I am never going to remember all this, next month or next year. I'm going to document this function before I go on:
function newProject ($rootdir, $newDir)
{
LESS THAN SYMBOL#
.SYNOPSIS
Creates a directory stucture for a C# in PowerShell project.
.DESCRIPTION
Creates a directory with the specified name and the following subdirectories:
Test, Code, Backup, Docs.
.PARAMETER rootdir
The directory which will host the top level directory of the project.
.PARAMETER newDir
The name of the new top-level project directory.
#GREATER THAN SYMBOL
pushd $rootdir
mkdir $newDir
cd $newDir
mkdir "Test"
mkdir "Code"
mkdir "Backup"
mkdir "Docs"
popd
}
Now, if you type the following:
get-help newProject
You get the following:
NAME
newProject
SYNOPSIS
Creates a directory stucture for a C# in PowerShell project.
SYNTAX
newProject [[-rootdir] LESS THAN SYMBOLObjectGREATER THAN SYMBOL] [[-newDir] LESS THAN SYMBOLObjectGREATER THAN SYMBOL] [LESS THAN SYMBOLCommonParametersGREATER THAN SYMBOL]
DESCRIPTION
Creates a directory with the specified name and the following subdirectories:
Test, Code, Backup, Docs.
RELATED LINKS
REMARKS
To see the examples, type: "get-help newProject -examples".
For more information, type: "get-help newProject -detailed".
For technical information, type: "get-help newProject -full".
Or if you type:
get-help newProject -full
You get this:
NAME
newProject
SYNOPSIS
Creates a directory stucture for a C# in PowerShell project.
SYNTAX
newProject [[-rootdir] LESS THAN SYMBOLObjectGREATER THAN SYMBOL] [[-newDir] LESS THAN SYMBOLObjectGREATER THAN SYMBOL] [LESS THAN SYMBOLCommonParametersGREATER THAN SYMBOL]
DESCRIPTION
Creates a directory with the specified name and the following subdirectories:
Test, Code, Backup, Docs.
PARAMETERS
-rootdir LESS THAN SYMBOLObjectGREATER THAN SYMBOL
The directory which will host the top level directory of the project.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters?
-newDir LESS THAN SYMBOLObjectGREATER THAN SYMBOL
The name of the new top-level project directory.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters?
LESS THAN SYMBOLCommonParametersGREATER THAN SYMBOL
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".
INPUTS
OUTPUTS
RELATED LINKS
Next up will be creating stubs for all the files I'll need. I did this on an ad hoc basis for the last project, so I'm just cutting and pasting and re-organizing. This is what I came up with:
stub.ps1:
pushd C:\Programming\PowerShellProg\stub
foreach ($a in dir .\Code) {
"CODE SCRIPT: $a"
invoke-expression "Code\$a" }
foreach ($a in dir .\Test) {
"TEST SCRIPT: $a"
invoke-expression "Test\$a" }
popd
CodeStub.ps1:
Add-Type @'
#define DEBUG
public class
{
// FIELDS
// CONSTRUCTORS
// PROPERTIES
// METHODS
#if DEBUG
// TESTING CODE
#endif
// OVERRIDES
}
'@
testStub.ps1:
# Testing TOPIC
#
#
#
#
#
#
#
#
# FUNCTIONS
#
#
#
#
#
# TEST DATA
#
#
#
#
#
#
# TESTS
#
#
#
#
#
# END Testing TOPIC
And I think that'll do for today.
On Monday, I'll start creating classes.
No comments:
Post a Comment