• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract datatype  RSS feed

 
Ranch Hand
Posts: 175
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 questions:
  • is it okay to refer to an object's interface as its abstract datatype?
  • is it okay to refer to an object's class as its concrete datatype?
  •  
    Sheriff
    Posts: 11494
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Joe Bishara wrote:I have 2 questions:
  • is it okay to refer to an object's interface as its abstract datatype?
  • is it okay to refer to an object's class as its concrete datatype?

  • The answer probably depends on the context in which you use these terms. I don't normally attach these meanings to those though, in any context.

    I refer to an object's interface, that is, the collection of its public members, as its "public API"
    If the object has members that are limited to package private (default) or protected access, I might refer to this as its "internal API"

    An object's concrete datatype is usually referred to as its "Runtime Type"
     
    Joe Bishara
    Ranch Hand
    Posts: 175
    17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks. I'm not sure about the context in which these terms can be used. I assumed that these terms can be used in any context because:
  • docs.oracle.com defines an interface as a reference type
  • wikipedia.org/wiki/Reference_type defines a reference type as a data type that refers to an object
  • wikipedia.org/wiki/Data_type defines an abstract data type as a data type that does not specify an implementation
  •  
    Junilu Lacar
    Sheriff
    Posts: 11494
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Joe Bishara wrote:Thanks. I'm not sure about the context in which these terms can be used. I assumed that these terms can be used in any context because:
  • docs.oracle.com defines an interface as a reference type
  • wikipedia.org/wiki/Reference_type defines a reference type as a data type that refers to an object
  • wikipedia.org/wiki/Data_type defines an abstract data type as a data type that does not specify an implementation

  • I'm not sure how you got these terms mixed up with terms you proposed. The terms you cited here are fairly standard. However, the terms you gave in your original post are not and to be honest, they just look wrong.

    In the phrase "an object's interface" - the word "interface" is something that the object has, which is true. An object does have an "interface" that is made up of any of its members that are accessible.

    In the phrase "an interface is a reference type" - the word "interface" refers to something totally different. In this sense, an interface is a program entity that just happens to be a reference type (as opposed to a primitive type, e.g. int, char, long, etc.) Additionally, an "interface" in this context is also an abstract type in the sense that it does not have a concrete implementation.

    For example, a java.util.List is an abstract type because it only defines the methods associated with any object that is a List. On the other hand, a java.util.ArrayList is a concrete class which implements the List interface. That is to say, ArrayList provides the implementations of the methods defined by the List interface. We say that ArrayList is a concrete implementation of the List interface/abstract type. Both ArrayList and List are reference types though because they are not any of the primitive data types.

    Clear as mud?
     
    Junilu Lacar
    Sheriff
    Posts: 11494
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Let me try to put this in more concrete terms

    Here, List<Integer> is an abstract data type. It is abstract because List only defines some methods. A List doesn't actually do anything. You need something that is a list (or implements the List interface) so that you can actually do something. But because you declare the type as List, this says that you don't really care what actually provides the implementaion of the methods/services defined by list, you just care that those methods/services will be provided somehow or other.

    It's like going to a store and asking for a Manager. You don't care who that manager is, as long as they can do things that a Manager can do. That's an "abstraction" and Manager.

    Now, let's say that after asking for a manager, a guy named Bob comes out to talk to you. You assume that Bob is a Manager and start asking Bob if you could get some help that only a Manager can give you. Bob obliges and you go along your merry way. Bob is the concrete implementation of the abstract idea of Manager.

    You, on the other hand, don't really care if it was Bob or Alice, another Manager, who came out and saw to your needs. You just cared that you got a hold of a Manager. In this way, you can say that Manager was the interface. Bob or Alice are the concrete implementations of Manager.

    The numbers variable is a reference variable because it points to (or references) an object. That object happens to be an ArrayList (a concrete implementation type). Since anything that is a List can only be an object and anything that is an ArrayList can only be an object (an int or char is not an object), any variable that is declared to be a List or ArrayList is a reference variable. Hence, List and ArrayList are also reference types (or reference data types if you like saying the complete term, but that's a mouthful).

    The variable a is a reference variable because it references an instance of Integer, which is a wrapper for a primitive int but an object nonetheless. Integer is a reference type because anything that is an Integer is an object.

    On the other hand, the variable c is declared as an int, which is a primitive data type. So we say that the variable c is a primitive, not a reference.

    I hope that kind of makes it a little clearer.
     
    Joe Bishara
    Ranch Hand
    Posts: 175
    17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Junilu Lacar wrote:Here, List<Integer> is an abstract data type

    This answers my original question. Correct me if I'm wrong but I would say that numbers is a reference to an object whose interface to the outside world is List (i.e. the public methods specified in this interface). In other words, List is the abstract data type of the object referenced by numbers. And ArrayList is its concrete data type.
     
    Marshal
    Posts: 56608
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    List is the abstract datatype whose interface is seen to the outside world in that example.
    ArrayList is another abstract datatype which happens to implement the same interface as List.
    Numbers = [1, 2, 3, 4, 5, 6] is a concrete example (=instance) of that/those abstract datatype/s.
    Counts = [83475, 873, -1, 0, 8374] is another concrete example.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!