locked
Primitive datatypes and compound datatypes? RRS feed

  • Question

  • Is it true that Primitive datatypes like int, string, decimal, etc have ONLY attributes and no behavior.

    Compound datatypes like bank account, etc have attributes and behavior?


    • Edited by bhattumang Wednesday, August 7, 2013 12:05 AM
    Wednesday, August 7, 2013 12:02 AM

Answers

  • What do you mean by

    Console.WriteLine(u.X); Has no meaning

    ?

    To me it means writes something to the console (under a few, simple assumptions - like that the code will compile and run without error and that this is the Console class that most people would expect, etc).  It will probably write 10 but that is not guaranteed, I would need to see the implementation of the field or property X.

    What do you mean by 'Technically we can write'?  How is it different from 'We can write'?  There is no (or very, very little) philosophy involved with setting a property to a value.

    In C#, 5 has behaviour.  It has at least the ToString,and the GetHashCode behaviours.

    Curious !

    Does this mean you are curious about something or that you find something to be curious?  Can you explain what it is that is curious to you?  Do you find it curious that a bank account can have money credited to it?  Why?

    If you have a question, please feel free to ask it.  You post seems to be a series of statements of dubious validity with no question.

    Your original post had questions. 

    "Is it true..."

    No it is not.  The opposite is true, however.  The int 5 has no attributes that I am aware of but it does have at least two behaviours, the behaviour of being able to create a string representation and the behaviour of being able to compute a hash code.

    Some compound types (I'm not 100% sure what your personal definition of 'compound' might be) will have Attributes and just the two behaviours mentioned, some will have many attributes and many behaviours.  Some will have just behaviours and no attributes.  You made a statement and put a question mark on the end of it so I am not sure exactly what the question was.  Where you asking if your statement was correct?  If so, I think the most correct statement would be

    Compound datatypes may have attributes and, like all types, have behaviour.

    (With the caveat that I am not quite sure what you mean by 'Compound')


    Paul Linton

    • Proposed as answer by Shyam Kr Wednesday, August 7, 2013 4:40 AM
    • Marked as answer by bhattumang Wednesday, August 7, 2013 6:10 AM
    Wednesday, August 7, 2013 3:44 AM

All replies

  • This is really a matter of semantics.  It's easy to make a "primitive" type with behavior or a "complex" type without behavior.

    There isn't really such a thing, in terms of the spec, as a "primitive" data type.  The main thing with the types you listed is that they are all immutable - so I would consider any immutable type to, by definition, not have "behavior" (though it could participate in behavior).  The only way to alter a string, for example, is to create a new string (the original one doesn't change), so it can be said that there is no "behavior" within the System.String class in that respect.

    Mutable types, like a "bank account", on the other hand, could define behaviors which affect their internal state or some other resource.



    Reed Copsey, Jr. - http://reedcopsey.com - If a post answers your question, please click Mark As Answer on that post. If you find a post helpful, please click Vote as Helpful.

    Wednesday, August 7, 2013 12:14 AM
  • But still writing

    SomeType t = new SomeType();

    t.X = 5;

    SomeType u = t;
    t.X = 10;

    Console.WriteLine(u.X); Has no meaning. 

    Technically we can write above code but Philosophically does it even make any sense. Value 5 (int value) is constant (possess only attribute) but no behavior. On other hand Bank Account which can contain Acc_No (int value Or attribute) and Credit method (behavior).

    Curious !


    • Edited by bhattumang Wednesday, August 7, 2013 12:30 AM
    Wednesday, August 7, 2013 12:28 AM
  • What do you mean by

    Console.WriteLine(u.X); Has no meaning

    ?

    To me it means writes something to the console (under a few, simple assumptions - like that the code will compile and run without error and that this is the Console class that most people would expect, etc).  It will probably write 10 but that is not guaranteed, I would need to see the implementation of the field or property X.

    What do you mean by 'Technically we can write'?  How is it different from 'We can write'?  There is no (or very, very little) philosophy involved with setting a property to a value.

    In C#, 5 has behaviour.  It has at least the ToString,and the GetHashCode behaviours.

    Curious !

    Does this mean you are curious about something or that you find something to be curious?  Can you explain what it is that is curious to you?  Do you find it curious that a bank account can have money credited to it?  Why?

    If you have a question, please feel free to ask it.  You post seems to be a series of statements of dubious validity with no question.

    Your original post had questions. 

    "Is it true..."

    No it is not.  The opposite is true, however.  The int 5 has no attributes that I am aware of but it does have at least two behaviours, the behaviour of being able to create a string representation and the behaviour of being able to compute a hash code.

    Some compound types (I'm not 100% sure what your personal definition of 'compound' might be) will have Attributes and just the two behaviours mentioned, some will have many attributes and many behaviours.  Some will have just behaviours and no attributes.  You made a statement and put a question mark on the end of it so I am not sure exactly what the question was.  Where you asking if your statement was correct?  If so, I think the most correct statement would be

    Compound datatypes may have attributes and, like all types, have behaviour.

    (With the caveat that I am not quite sure what you mean by 'Compound')


    Paul Linton

    • Proposed as answer by Shyam Kr Wednesday, August 7, 2013 4:40 AM
    • Marked as answer by bhattumang Wednesday, August 7, 2013 6:10 AM
    Wednesday, August 7, 2013 3:44 AM
  • With huge smile on my face :) I am saying THANKS! I was trapped in thoughts and was trying to digest concept which was tiring.  

    "Has no meaning. " was for entire code and not Console.WriteLine(u,X); that was my typo. I wanted to make a point saying below code is confusing and as no meaning to code in such a way. we can simply write int i = 5; instead of creating object to sometype.

    About attribute and behavior I got my point from your explanation. I was wrong on that part :\ 

    SomeType t = new SomeType();

    t.X = 5;

    SomeType u = t;
    t.X = 10;

    Console.WriteLine(u.X); 

    Understood Sir!!


    • Edited by bhattumang Wednesday, August 7, 2013 6:18 AM
    Wednesday, August 7, 2013 6:10 AM