Jump to content

OOP design question


Recommended Posts

That's a sequence diagram.

No, not what I was thinking. Class diagram as you pointed out is a good start.

I would also show the interactions and required data between the classes after I had created the Use Cases.

From there implementation would be straight forward.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • Replies 49
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

No, not what I was thinking. Class diagram as you pointed out is a good start.

I would also show the interactions and required data between the classes after I had created the Use Cases.

From there implementation would be straight forward.

The order is this:

- (Functional requirements)

- Use case

- Class diagram

- Sequence diagram

A class diagram is something static that doesn't change over time and has no specific order. To show the interactions between classes, a sequence diagram should be created.

This all is modeled after you know the requirements, and have modeled the use cases. Typically, one sequence diagram is created per use case.

Link to comment
Share on other sites

Yoriz, I've noticed that you pass .Prisoner1 to the makeLeadPrisoner function.

$oSelf.MakeLeadPrisoner($oSelf.Prisoner1)

Where does Prisoner1 come from? I don't see where it is a method or a property.

Link to comment
Share on other sites

Prisoner1 is from _oPrisoner, created along with the other 22 prisoners.

Func _oPrison_AddPrisoners($oSelf)
    For $i = 1 To $oSelf.PrisonerQty Step 1
        _AutoItObject_AddProperty($oSelf, "Prisoner" & $i, $ELSCOPE_READONLY, _oPrisoner($i))
    Next
    Return $oSelf
EndFunc   ;==>_oPrison_AddPrisoners

edit : i guess you never noticed previous reply to your lead prisoner question

The Lead Prisoner is just one of the prisoners Func _oLeadPrisoner($oPrisoner) that has been given his own individual version of method 'MovedToSwitchRoom' and an additional method 'HasAllSwitched' and has two extra propertys 'SwitchRoomCount' and 'LastVisitDidISwitchOn' everything else is shared with the other prisoners.

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Here's the latest version of my LightBulb/Switch program:

If you have a minute then please take a look and tell me your thoughts. I'd like to hear them.

Edit: allright, well, this is some epic fail lulz

#include "AutoItObject.au3"

_AutoItObject_Startup()

Global $oError = ObjEvent("Autoit.Error", "_myErrFunc")

Global $GenericDevice = ElectricalDevice()

$GenericDevice.Toggle()
$GenericDevice.Toggle()

#region Generic Electrical Device
Func ElectricalDevice()
    Local $self = _AutoItObject_Create()
    _AutoItObject_AddProperty($self, "State", $ELSCOPE_PRIVATE, True)
    _AutoItObject_AddMethod($self, "Toggle", "_toggle")
    _AutoItObject_AddMethod($self, "DisplayState", "_displayState")
    _AutoItObject_AddMethod($self, "CreateDevice", "_createDevice")
    $self.CreateDevice("LightBulb")
    $self.CreateDevice("Switch")
    Return $self
EndFunc ;==>ElectricalDevice

Func _createDevice($self, $deviceName)
    $self = StringStripWS($deviceName, 8)
    _AutoItObject_AddProperty($self, $deviceName)
    Return $self
EndFunc ;==>_createDevice

Func _displayState($self)
    MsgBox(0, '', $self.State)
EndFunc ;==>_displayState

Func _toggle($self)
    $self.State = Not $self.State
    $self.DisplayState()
    Return $self
EndFunc ;==>_toggle
#endregion Generic Electrical Device

Func _ErrFunc()
    ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
EndFunc ;==>_ErrFunc

1st version:

#include "AutoItObject.au3"
_AutoItObject_Startup()

Global $oError = ObjEvent("Autoit.Error", "_myErrFunc")

Global $lightBulb = LightBulbObj()
Global $Switch = SwitchObj()

$Switch.Flip()

$Switch.Flip()

#region LightBulb Class
Func LightBulbObj()
 Local $self = _AutoItObject_Create()
 _AutoItObject_AddProperty($self, "BulbState", $ELSCOPE_PRIVATE, False)
 _AutoItObject_AddMethod($self, "Output", "_declareBulbState", True)
 _AutoItObject_AddMethod($self, "Flip", "_changeBulbState")
 Return $self
EndFunc ;==>LightBulbObj

Func _declareBulbState($self)
 MsgBox(0, "Light Bulb", $self.BulbState)
EndFunc ;==>_declareBulbState

Func _changeBulbState($self)
 $self.BulbState = Not $self.BulbState
 $self.Output()
EndFunc ;==>_changeBulbState
#endregion LightBulb Class

#region LightSwitch Class
Func SwitchObj()
 Local $self = _AutoItObject_Create()
 _AutoItObject_AddProperty($self, "SwitchState", $ELSCOPE_PRIVATE, False)
 _AutoItObject_AddMethod($self, "Flip", "_flipSwitch")
 _AutoItObject_AddMethod($self, "Output", "_declareSwitchState", True)
 Return $self
EndFunc ;==>SwitchObj

Func _declareSwitchState($self)
 MsgBox(0, "Light Bulb", $self.SwitchState)
EndFunc ;==>_declareSwitchState

Func _flipSwitch($self)
 $lightBulb.Flip()
 $self.SwitchState = Not $self.SwitchState
EndFunc ;==>_flipSwitch
#endregion LightSwitch Class

Func _ErrFunc()
 ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
EndFunc ;==>_ErrFunc

Edited by jaberwocky6669
Link to comment
Share on other sites

Hmm yea you dont have much actually happening here, ElectricalDevice() has two propertys Lightbulb & switch that dont store any values or have any influence on the outcome, and its self has a property state and a method toggle that returns only a meaningless true or false. sorry :idea:

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

The order is this:

- (Functional requirements)

- Use case

- Class diagram

- Sequence diagram

A class diagram is something static that doesn't change over time and has no specific order. To show the interactions between classes, a sequence diagram should be created.

This all is modeled after you know the requirements, and have modeled the use cases. Typically, one sequence diagram is created per use case.

I am aware of the SDLC. My recommendation to jaberwocky6669 was not to jump into the code before you have a good understanding on what you want to code. As pointed out, there are a number of ways to define the solution space.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

I hope this isn't considered resurrecting an old thread.

Here's my latest version of my switch lightbulb oo program. This time I added a circuit class to act as an interface as suggested by previous posters. Any advice that you can give will be much appreciated. I loosely followed some code previously posted by Yoriz.

#include "AutoItObject.au3"

_AutoItObject_Startup()

Global $oError = ObjEvent("Autoit.Error", "_myErrFunc")
Func _ErrFunc()
    ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
EndFunc ;==>_ErrFunc

Global $switch = SwitchObj()

$switch.Toggle
$switch.Toggle

Exit

#region Switch Class
Func SwitchObj()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "CircuitObj", $ELSCOPE_PRIVATE, CircuitObj())
    _AutoItObject_AddMethod($this, "Toggle", "_toggle")
    Return $this
EndFunc ;==>SwitchObj

Func _toggle($this)
    $this.CircuitObj.Toggle()
EndFunc ;==>_toggle
#endregion Switch Class

#region Lightbulb Class
Func LightBulbObj()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "State", $ELSCOPE_PRIVATE, True)
    _AutoItObject_AddProperty($this, "Name", $ELSCOPE_PRIVATE, "LightBulb")
    _AutoItObject_AddMethod($this, "Announce", "_lbannounce", True)
    _AutoItObject_AddMethod($this, "Toggle", "_lbToggle")
    Return $this
EndFunc ;==>LightBulbObj

Func _lbToggle($this)
    $this.State = Not $this.State
    $this.Announce()
EndFunc ;==>_lbToggle

Func _lbannounce($this)
    MsgBox(0, $this.Name, $this.State)
EndFunc ;==>_lbannounce
#endregion Lightbulb Class

#region CircuitObj Class
Func CircuitObj()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "LightBulb", $ELSCOPE_PRIVATE, LightBulbObj())
    _AutoItObject_AddMethod($this, "Toggle", "_currentFlow")
    Return $this
EndFunc ;==>CircuitObj

Func _currentFlow($this)
    $this.LightBulb.Toggle()
EndFunc ;==>_currentFlow
#endregion CircuitObj Class
Link to comment
Share on other sites

I think its time to move on from the light bulb and approach solving something else, try a puzzle like 23 prisoners or something.

I also think that its best not to ask here in the developer chat oop question about autoit, as its been stated in this thread autoit is not oop and just winds people up.

If you have problems again i think you may get a better response if it's posted in 'general help and support' and include in the title 'need help with script using AutoitObject UDF'.

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Ok, good idea, my apologies. Thanks. This is the only forum where I've ever made more than a handful of posts so I never got the hang of forum netiquette.

Edited by jaberwocky6669
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...