I like to use Objective-c style of createObject instead of the normal new.
Basically it make it easier for me to just create a basic object and then initialize the variable. Sometimes when I want to create an object of derived class, I simply call a class that initiate the base class.
Also sometimes, often in fact, I want to do some things first before initializing say, the base class, or most of the basic variables.
Something like this
Public Shared Function createOrders(amount As String, base As String, quote As String, exchange As ExchangesClass, time As String, price As String, id As String, sellinginsteadofbuying As String, identifyingText As String) As OrderAlreadyPlacedAtanExchange
Debug.Assert(base <> "")
Debug.Assert(quote <> "")
Debug.Assert(price <> "")
Dim a = New OrderAlreadyPlacedAtanExchange
a.InitializeForBasicSimpleOrder(amount, price, base, quote, exchange, sellinginsteadofbuying, identifyingText)
time = IIf(time = "", "1-1-2000", time).ToString
a._timeOrderPlaced = Date.Parse(time)
a._id = id
If quote = "IFLT" Then
Dim b = 1
End If
Return a
End Function
Basically what happened is that the class OrderAlreadyPlacedAtanExchange
inherits from class BasicSimpleOrder
.
Class OrderAlreadyPlacedAtanExchange
Inherits BasicSimpleOrder
So if I am doing it my way I create an object of type OrderAlreadyPlacedAtanExchange
but then I can initialize the base class of the object with
a.InitializeForBasicSimpleOrder(amount, price, base, quote, exchange, sellinginsteadofbuying, identifyingText)
Since using json.net I am interested in doing it the normal way.
But how can a constructor (or new sub) of OrderAlreadyPlacedAtanExchange
initialize their parents?
Should a constructor of OrderAlreadyPlacedAtanExchange
called a constructor of BasicSimpleOrder
? But then I'll be getting an object of type BasicSimpleOrder
If that's the case then I should keep function InitializeForBasicSimpleOrder
and get a new sub to call it then?