![]() |
Click here to advertise with us
|
|
|||||||
| VB.NET General Discussion VB.NET general discussion area |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello.
I'm new to OOP and am racking my brain over what to name stuff... I have read a lot of different articles on standards and when to use nouns and different case, etc... I'm stumped when it comes to a real world example. In the code below, the namespace is called "Navigation" which I think is correct. Then I have a class called "Heading", which by definition is the direction a person/vehicle is truly pointing towards. I think that is also named correctly. In the code below, I have four things I have named: _WhatToName1, WhatToName2, WhatToName3, and WhatToName4. The value that gets passed in and stored is a double between 0 and 360 -- essentially the degree value from a circle. For WhatToName3 and WhatToName4, I have seen a lot of places that just use "value" as the name. Is that standard? Code:
Namespace Navigation
Public Class Heading
Private _WhatToName1 As Double
Public Sub New(ByVal WhatToName3 As Double)
Me.WhatToName2 = WhatToName3
End Sub
Public Property WhatToName2() As Double
Get
Return _WhatToName1
End Get
Set(ByVal WhatToName4 As Double)
_WhatToName1 = WhatToName4
End Set
End Property
End Class
End Namespace
Thanks in advance for your help, Stephen |
|
||||
|
Hello.
First question, are you developing a FLOSS application, Closed-Source Library (for resale) or a Closed-Source Application? In the last case, I'd stick with naming convention YOU can live with...in the other two cases it is most important that the interface of the code is intuitive. In the first two cases make sure to use XML-Documentation. Code:
Navigation.Heading.Direction 'leads me to something what points into a direction Bobby
__________________
Don't give TypeCasting Errors a chance, turn ON Option Strict! Greatest Obfuscator ever: EazFuscator (Freeware) Greatest Reflection Tool ever: .NET Reflector (Freeware) with Add-Ins Greatest Introspection Tool ever: Gendarme (GPL) Greatest MySQL FrontEnd ever: MySQL-Front (Shareware), HeidiSQL (GPL) |
|
||||
|
WhatToName2: Direction as suggested is a good property name for this.
WhatToName1: _direction would be my choice. WhatToName3: direction is the guidelines suggestion in this case. WhatToName4: value is put here by the property snippet, it is also commonly used in the .Net library. Guidelines for Names
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
|||
|
Quote:
For 3, I prefer to defy convention and use "whatDirection" as I feel "Me.Direction = direction" is messy. Purely my personal preference though. |
|
||||
|
Quote:
Quote:
Whether is was "Me.Direction = direction" (setting value through property setter) or "Me._direction = direction" (setting value to private field) is just a matter of reuse of existing code if necessary, for example when setter does validation.
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
|||
|
Thanks everyone. This is very helpful and I think I am getting the hang of it. I have another one that is exactly the same but is for Bearing ("The direction of one object in relation to another object"). So that one would be Navigation.Bearing.Direction right?
Last question: I have another class, the same as above, which is called "Speed". It is used to hold meters per second. I am using it for this GPS app but I don't think it should go into the Navigation namespace as it could be related to stuff other than navigation, right? For the property name of this class, would I want to name it something like "MetersPerSecond" or is that a no no? Stephen |
|
||||
|
Quote:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms MSDN: Data Walkthroughs | "How Do I?" Videos My Blog: Custom Events | Dynamic GDI+ Drawing |
|
|||
|
Okay. I think this makes sense, to me anyways:
Code:
Namespace GPS
Public Class Speed
Private _metersPerSecond As Double
Public Sub New(ByVal metersPerSecond As Double)
Me.MetersPerSecond = metersPerSecond
End Sub
Public Property MetersPerSecond() As Double
Get
Return _metersPerSecond
End Get
Set(ByVal value As Double)
If value < 0 Then Throw New ArgumentOutOfRangeException("Speed cannot be less than 0.")
_metersPerSecond = value
End Set
End Property
End Class
End Namespace
|
|
||||
|
That still doesn't make sense. Consider this. If you had a Car class would it make sense to say myCar.Speed.MetersPerSecond = 10? That doesn't make sense to me. What does make sense is myCar.Speed = 10. The Car class would have a Speed property of type Double and you would validate the value inside that property. Having a whole separate class for speed is not appropriate.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms MSDN: Data Walkthroughs | "How Do I?" Videos My Blog: Custom Events | Dynamic GDI+ Drawing |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|