locked
How the best way? RRS feed

  • Question

  • User1345609001 posted

    Hey guys,
    A friend in work suggested the use on classe to store the parameters BEFORE call a method. He's said this is called "Abstract Class".

    My "know how" of VB.NET is small... so, I want to know of you what mode is the best way:

    Call a function/sub like that:

    sub foo(byval p1 as integer)
    'do the things with parameter p1
    end sub

    or that way:

    class dataxxx
    protected property p1 as integer
    end class

    sub new()
    'do the things with dataxxx.p1 property
    end sub

    When I programmed in VB 6 don't have this kind of discussion... lol...

    Thursday, January 5, 2012 3:56 PM

Answers

  • User-952121411 posted

    Your friend is correct. His code is utilizing Object Oriented Programming ways, and that was something difficult to do or understand as VB6 developers (I know I used to be one 10 years ago), so it's OK.

    The property on the class allows creation of an instance of it which makes an 'Object'. The object is reusable and has data (properties) and behavior (methods) to describe it. With your code there is no consistent or understood behavior: just code that lives on its own and is not reusable or scalable. You have to recreate the value for p1 each time you need it, or even worse, create a Global Public variable to store the data.

    I recommend reading up on some introductory information on Object Oriented Programming. You might be able to work with your friend at work to have him help you with writing code using Object Oriented principals. The following link may help get you started:

    Object-Oriented Programming in Visual Basic .NET:
    http://msdn.microsoft.com/en-us/library/aa289512(vs.71).aspx

    Good luck! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 13, 2012 11:29 AM

All replies

  • User-1629487188 posted

    i do not know why your firend suggested using abstract classes, i do not understand from what you wrote what were you trying to achieve,

    anyway, take a look at what is abstract class

    http://msdn.microsoft.com/en-us/library/k535acbf%28v=vs.71%29.aspx

    Friday, January 6, 2012 10:24 AM
  • User1345609001 posted
    Humm... it's interesting.

    But it's really necessary or it's "best pratice" use this kind of class to call a method?

    I realy don't see sense to do that kind of thing...
    It Just uses more resources of server, I think. But, I'm here to learning with masters of ASP.NET.... lol.

    Regards.
    Tuesday, January 10, 2012 10:07 AM
  • User-952121411 posted

    Your friend is correct. His code is utilizing Object Oriented Programming ways, and that was something difficult to do or understand as VB6 developers (I know I used to be one 10 years ago), so it's OK.

    The property on the class allows creation of an instance of it which makes an 'Object'. The object is reusable and has data (properties) and behavior (methods) to describe it. With your code there is no consistent or understood behavior: just code that lives on its own and is not reusable or scalable. You have to recreate the value for p1 each time you need it, or even worse, create a Global Public variable to store the data.

    I recommend reading up on some introductory information on Object Oriented Programming. You might be able to work with your friend at work to have him help you with writing code using Object Oriented principals. The following link may help get you started:

    Object-Oriented Programming in Visual Basic .NET:
    http://msdn.microsoft.com/en-us/library/aa289512(vs.71).aspx

    Good luck! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 13, 2012 11:29 AM