12 Replies - 400 Views - Last Post: 28 February 2012 - 12:01 PM Rate Topic: -----

#1 shadachi  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 25-January 08

Question : Better way to Return an object ?

Posted 27 February 2012 - 01:27 AM

Hi guys ,

I would like to ask whether is there a better way to return an object.

For example.



Object Class with properties

Public class objProps

    Property ORDERNUM() As String
    Property OWNER() As String
    Property INFO1() As String
    Property INFO2() As String

End Class 





Runtime class where all the methods will be in here

Public class runTimeClass
       inherits objProps




Public function FillData() As runTimeClass

  Dim x as new RunTimeClass()

'' filling the object 
   x.ORDERNUM = "111"
   x.OWNER = "TEST"
   x.INFO1= "123"
   x.INFO2 = "pop"

  return x

End function

End class





'' This is a console program..
Public Class MainClass



Sub Main () 


 Dim x as new RunTimeClass()

  x = x.FillData()


  console.writeline( x.ORDERNUM )

End sub 

End Class




In this main class , the portion where
 x = x.FillData()




Are there any other efficient ways ? Greatly appreciated if anyone could provide some suggestions or samples =)

Is This A Good Question/Topic? 0
  • +

Replies To: Question : Better way to Return an object ?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,656
  • Joined: 02-June 10

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 08:37 AM

Have you even tried to run this code? Because I suspect it should fail due to inconsistent case usage in your names.

01 Public class runTimeClass
08 Dim x as new RunTimeClass()

Otherwise, I'm missing the point to this post. Is there a problem/error?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 09:49 AM

tlhIn`toq: VB.net is case-insensitive.

shadachi: What do you mean by "Are there any other efficient ways ?"
Efficient how?

This post has been edited by AdamSpeight2008: 27 February 2012 - 09:51 AM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,656
  • Joined: 02-June 10

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 09:51 AM

View PostAdamSpeight2008, on 27 February 2012 - 10:49 AM, said:

VB.net is case-insensitive.

Wow, really? Learn something new every day. That must make it harder on people making the transition into other languages; having to go from being sloppy to paying attention.
Was This Post Helpful? 1
  • +
  • -

#5 shadachi  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 25-January 08

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 04:55 PM

Sorry for the late reply..

Sorry for the sloppy case problem. but yes it is a workable code . Just that this is not a full set of codes =D

@Adam , Yes . Is it a common practice where we use like the following to reference the object in order for the object to fill its properties? If So , wouldn't it be messy ?

 	 Dim x as new RunTimeClass()
	 
	  x = x.FillData()





2nd question , Is it possible to do like the following without the referencing like x = x.FillData() , what impact will it make ?

 Dim x as new RunTimeClass()

  x.FillData()


This post has been edited by shadachi: 27 February 2012 - 05:00 PM

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 07:18 PM

I'm thinking in your filldata method you could just use a sub and then use mybase.{Property} = ???

Then in your sub Main you would use

Dim x as new RunTimeClass

x.FillData

Was This Post Helpful? 1
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 07:47 PM

Is there any reason preventing from using constructors?

This post has been edited by AdamSpeight2008: 27 February 2012 - 08:01 PM

Was This Post Helpful? 0
  • +
  • -

#8 shadachi  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 25-January 08

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 10:14 PM

@CharlieMay , thx . would give that a try . Mybase.{property}

@Adam , Well... This is just one of the methods in the RunTime class , there are many other more methods within.. that's why i don't use the constructors for this function. xD


UPDATE *

I did it .. XD thx Charlie and Adam for the help..

What i did was changed it to sub first instead of a function . Used Me.{Property}

Public Sub FillData() As runTimeClass
	 
	 
	 
	'' filling the object
	   me.ORDERNUM = "111"
	   me.OWNER = "TEST"
	   me.INFO1= "123"
	   me.INFO2 = "pop"
	 	 
	End Sub



This post has been edited by shadachi: 27 February 2012 - 10:21 PM

Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 10:22 PM

I think if you read the Inheritance Tutorial, you'll get what I mean.
Was This Post Helpful? 1
  • +
  • -

#10 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 10:27 PM

View PostAdamSpeight2008, on 28 February 2012 - 03:22 PM, said:

I think if you read the my Inheritance Tutorial, you'll get what I mean.

I just read it myself. Good work!
Was This Post Helpful? 0
  • +
  • -

#11 shadachi  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 25-January 08

Re: Question : Better way to Return an object ?

Posted 27 February 2012 - 11:25 PM

Awesome Tutorial Adam..It actually allowed me to look at inheritance from a different perspective ..

oh yea..just to let u know if not mistaken

X:= 4 Y:= 5 Z:=0



shouldn't it be in the output section
X:= 4 Y:= 5 Z:=6



and oh yea.. this part i don't really understand. The colon operator u've used.

 _Angle = Angle : _Distance = Distance


This post has been edited by shadachi: 27 February 2012 - 11:39 PM

Was This Post Helpful? 1
  • +
  • -

#12 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Question : Better way to Return an object ?

Posted 28 February 2012 - 01:00 AM

View Postshadachi, on 28 February 2012 - 04:25 PM, said:

Awesome Tutorial Adam..It actually allowed me to look at inheritance from a different perspective ..

oh yea..just to let u know if not mistaken

X:= 4 Y:= 5 Z:=0



shouldn't it be in the output section
X:= 4 Y:= 5 Z:=6



and oh yea.. this part i don't really understand. The colon operator u've used.

 _Angle = Angle : _Distance = Distance


The colon operator is used to combine multiple statements together. It can lead to dense and cluttered lines but when used in moderation (like Adam's example) and to join relatively related statements it is fine. There is nothing wrong with them when used appropriately :)
Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Question : Better way to Return an object ?

Posted 28 February 2012 - 12:01 PM

Well spotted
Read the reply to the tutorial.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1