Loading ...
Sorry, an error occurred while loading the content.
 

Re: [dpsg-nyc] A small problem...

Expand Messages
  • oleg shteynbuk
    It is in Java I guess. You can use clone in class T, then you don t need to write inner class, not sure why you need to cast from derived to base class. Also
    Message 1 of 9 , Aug 1, 2003
      It is in Java I guess.

      You can use clone in class T, then you don't need to
      write inner class, not sure why you need to cast from
      derived to base class. Also Java clone, if you use
      clone from the Object class, have some problems, it
      could be used but with care.

      You can use factory method to return the right type of
      the object or its variant using Class object.
      So runtime equivalent of
      "new T" could be "T.getClass.newInstanse()"

      Factory Method was actually last week topic :)

      Oleg

      --- viswadeep veguru <veguru_deep@...> wrote:
      > HI,
      > Let me tell you what's my probelem context is.
      > I need to write a code to iterate throw a set of
      > objects and do some operations on them and return
      > that
      > Ovject.
      > let that type be "T", now i need to get the instance
      > of "T" which is should be return type for my method.
      >
      > How do I create a Object of type "T" which is not
      > know
      > to me till runtime...
      > I can not say T t = new T()..
      >
      >
      > What happens if i write an Small Inner class which
      > extends "T" and will createa a clone of it self and
      > type cast to its parent.. and return a T
      > Is that a good design....
      >
      >
      > Please do give some pointer to solve this..
      >
      > with regs
      > viswadeep veguru.
      >
      >
      >
      > __________________________________
      > Do you Yahoo!?
      > Yahoo! SiteBuilder - Free, easy-to-use web site
      > design software
      > http://sitebuilder.yahoo.com
      >


      __________________________________
      Do you Yahoo!?
      Yahoo! SiteBuilder - Free, easy-to-use web site design software
      http://sitebuilder.yahoo.com
    • Ray Ye
      Hi Viswadeep, I don t quite understand your problem yet. Now that you can iterate through the list of objects whose type are T , why could not you just return
      Message 2 of 9 , Aug 1, 2003
        Hi Viswadeep,

        I don't quite understand your problem yet. Now that you can iterate through
        the list of objects whose type are "T", why could not you just return them
        as they are? If you don't know it is the type "T", how could you invoke
        methods on it (or how do you know which methods you could invoke)?

        If your situation is you have object A whose type is "R" and object B whose
        type is "S" in the list, where "R" and "S" are subtypes of "T", and the
        methods you want to invoke belong to "T", and you want to return a specific
        type of either "R" or "S", then it is a bit hard. It depends on what
        languages you are using, if you are using C++, I am not sure how you would
        do it. But if you are using Java, you can utilize the reflection API.

        Hope this helps,

        Cheers,

        Ray

        -----Original Message-----
        From: viswadeep veguru [mailto:veguru_deep@...]
        Sent: Friday, August 01, 2003 2:25 AM
        To: dpsg-nyc@yahoogroups.com
        Subject: [dpsg-nyc] A small problem...


        HI,
        Let me tell you what's my probelem context is.
        I need to write a code to iterate throw a set of
        objects and do some operations on them and return that
        Ovject.
        let that type be "T", now i need to get the instance
        of "T" which is should be return type for my method.

        How do I create a Object of type "T" which is not know
        to me till runtime...
        I can not say T t = new T()..


        What happens if i write an Small Inner class which
        extends "T" and will createa a clone of it self and
        type cast to its parent.. and return a T
        Is that a good design....


        Please do give some pointer to solve this..

        with regs
        viswadeep veguru.



        __________________________________
        Do you Yahoo!?
        Yahoo! SiteBuilder - Free, easy-to-use web site design software
        http://sitebuilder.yahoo.com


        To Unsubscribe, send a blank message to: dpsg-nyc-unsubscribe@...


        Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      • viswadeep veguru
        Thanks oleg shteynbuk, and Ray Ye for replying.. Reflection could be a solution. But i was searching for other way method. Let me again explaing u clearly. I
        Message 3 of 9 , Aug 2, 2003
          Thanks
          oleg shteynbuk, and Ray Ye for replying..

          Reflection could be a solution.
          But i was searching for other way method.

          Let me again explaing u clearly.
          I have a util class where i have Iterator of Objects
          T.
          restrict T such that it implements X. so i know what
          all methods to invoke on T.
          now i need to create a Object T and return.

          Small example is, finding average of an Iterator of T
          expect T implements X and X has both addition and
          division operations defined. i should return average
          in type T.

          I guess i could explain u more clearly.

          with regs
          Viswa deep.




          --- Ray Ye <rayye@...> wrote:
          > Hi Viswadeep,
          >
          > I don't quite understand your problem yet. Now that
          > you can iterate through
          > the list of objects whose type are "T", why could
          > not you just return them
          > as they are? If you don't know it is the type "T",
          > how could you invoke
          > methods on it (or how do you know which methods you
          > could invoke)?
          >
          > If your situation is you have object A whose type is
          > "R" and object B whose
          > type is "S" in the list, where "R" and "S" are
          > subtypes of "T", and the
          > methods you want to invoke belong to "T", and you
          > want to return a specific
          > type of either "R" or "S", then it is a bit hard. It
          > depends on what
          > languages you are using, if you are using C++, I am
          > not sure how you would
          > do it. But if you are using Java, you can utilize
          > the reflection API.
          >
          > Hope this helps,
          >
          > Cheers,
          >
          > Ray
          >
          > -----Original Message-----
          > From: viswadeep veguru
          > [mailto:veguru_deep@...]
          > Sent: Friday, August 01, 2003 2:25 AM
          > To: dpsg-nyc@yahoogroups.com
          > Subject: [dpsg-nyc] A small problem...
          >
          >
          > HI,
          > Let me tell you what's my probelem context is.
          > I need to write a code to iterate throw a set of
          > objects and do some operations on them and return
          > that
          > Ovject.
          > let that type be "T", now i need to get the instance
          > of "T" which is should be return type for my method.
          >
          > How do I create a Object of type "T" which is not
          > know
          > to me till runtime...
          > I can not say T t = new T()..
          >
          >
          > What happens if i write an Small Inner class which
          > extends "T" and will createa a clone of it self and
          > type cast to its parent.. and return a T
          > Is that a good design....
          >
          >
          > Please do give some pointer to solve this..
          >
          > with regs
          > viswadeep veguru.
          >
          >
          >
          > __________________________________
          > Do you Yahoo!?
          > Yahoo! SiteBuilder - Free, easy-to-use web site
          > design software
          > http://sitebuilder.yahoo.com
          >
          >
          > To Unsubscribe, send a blank message to:
          > dpsg-nyc-unsubscribe@...
          >
          >
          > Your use of Yahoo! Groups is subject to
          > http://docs.yahoo.com/info/terms/
          >
          >


          =====
          with regs
          viswa deep

          __________________________________
          Do you Yahoo!?
          Yahoo! SiteBuilder - Free, easy-to-use web site design software
          http://sitebuilder.yahoo.com
        • Ray Ye
          Hi Viswa, If T implements X (which is an interface), and you really want to return T during the iteration(which I don t know the reason, since X could have
          Message 4 of 9 , Aug 5, 2003
            Hi Viswa,

            If T implements X (which is an interface), and you really want to return T
            during the iteration(which I don't know the reason, since X could have
            multiple implementations other than T), and you are sure that your iterator
            only returns T and no other types of objects that implement X, and you
            refuse to use reflection, then in your interface X, you could add a method
            to return an object of type T, and let you T implements X and return itself
            for this method.

            There are a lot of problems with this design. One of them is to couple the
            abstraction (interface X) with the implemention(class T). All the clients
            using interface X now would be forced to change or recompile if T is
            changes, which these clients would not be interested in T at all. But if you
            really want to pay for this price, and are sure it would not cause any
            problems, then go for it.

            Other people may have better ideas. Hope this helps you.

            Cheers,

            Ray

            -----Original Message-----
            From: viswadeep veguru [mailto:veguru_deep@...]
            Sent: Sunday, August 03, 2003 2:01 AM
            To: dpsg-nyc@yahoogroups.com
            Subject: RE: [dpsg-nyc] A small problem...


            Thanks
            oleg shteynbuk, and Ray Ye for replying..

            Reflection could be a solution.
            But i was searching for other way method.

            Let me again explaing u clearly.
            I have a util class where i have Iterator of Objects
            T.
            restrict T such that it implements X. so i know what
            all methods to invoke on T.
            now i need to create a Object T and return.

            Small example is, finding average of an Iterator of T
            expect T implements X and X has both addition and
            division operations defined. i should return average
            in type T.

            I guess i could explain u more clearly.

            with regs
            Viswa deep.




            --- Ray Ye <rayye@...> wrote:
            > Hi Viswadeep,
            >
            > I don't quite understand your problem yet. Now that
            > you can iterate through
            > the list of objects whose type are "T", why could
            > not you just return them
            > as they are? If you don't know it is the type "T",
            > how could you invoke
            > methods on it (or how do you know which methods you
            > could invoke)?
            >
            > If your situation is you have object A whose type is
            > "R" and object B whose
            > type is "S" in the list, where "R" and "S" are
            > subtypes of "T", and the
            > methods you want to invoke belong to "T", and you
            > want to return a specific
            > type of either "R" or "S", then it is a bit hard. It
            > depends on what
            > languages you are using, if you are using C++, I am
            > not sure how you would
            > do it. But if you are using Java, you can utilize
            > the reflection API.
            >
            > Hope this helps,
            >
            > Cheers,
            >
            > Ray
            >
            > -----Original Message-----
            > From: viswadeep veguru
            > [mailto:veguru_deep@...]
            > Sent: Friday, August 01, 2003 2:25 AM
            > To: dpsg-nyc@yahoogroups.com
            > Subject: [dpsg-nyc] A small problem...
            >
            >
            > HI,
            > Let me tell you what's my probelem context is.
            > I need to write a code to iterate throw a set of
            > objects and do some operations on them and return
            > that
            > Ovject.
            > let that type be "T", now i need to get the instance
            > of "T" which is should be return type for my method.
            >
            > How do I create a Object of type "T" which is not
            > know
            > to me till runtime...
            > I can not say T t = new T()..
            >
            >
            > What happens if i write an Small Inner class which
            > extends "T" and will createa a clone of it self and
            > type cast to its parent.. and return a T
            > Is that a good design....
            >
            >
            > Please do give some pointer to solve this..
            >
            > with regs
            > viswadeep veguru.
            >
            >
            >
            > __________________________________
            > Do you Yahoo!?
            > Yahoo! SiteBuilder - Free, easy-to-use web site
            > design software
            > http://sitebuilder.yahoo.com
            >
            >
            > To Unsubscribe, send a blank message to:
            > dpsg-nyc-unsubscribe@...
            >
            >
            > Your use of Yahoo! Groups is subject to
            > http://docs.yahoo.com/info/terms/
            >
            >


            =====
            with regs
            viswa deep

            __________________________________
            Do you Yahoo!?
            Yahoo! SiteBuilder - Free, easy-to-use web site design software
            http://sitebuilder.yahoo.com


            To Unsubscribe, send a blank message to: dpsg-nyc-unsubscribe@...


            Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
          • viswadeep veguru
            Thanks Ray Ye, for ur replay, I guess i lost a point T in my context its a Template classe c++ , or I meen it any class that implements X thats what i mean, ur
            Message 5 of 9 , Aug 6, 2003
              Thanks Ray Ye, for ur replay,
              I guess i lost a point T in my context its a Template
              classe c++ , or I meen it any class that implements X
              thats what i mean, ur solution to generate a T
              instance from X interface declaration.. is ok.
              But i am writing code in java will i have change even
              if i use a generics. I don't think u can have boundary
              conditions in return type.
              I meen if u have to declare such a method in side x
              it should like this right
              public interface X {

              }

              --- Ray Ye <rayye@...> wrote:
              > Hi Viswa,
              >
              > If T implements X (which is an interface), and you
              > really want to return T
              > during the iteration(which I don't know the reason,
              > since X could have
              > multiple implementations other than T), and you are
              > sure that your iterator
              > only returns T and no other types of objects that
              > implement X, and you
              > refuse to use reflection, then in your interface X,
              > you could add a method
              > to return an object of type T, and let you T
              > implements X and return itself
              > for this method.
              >
              > There are a lot of problems with this design. One of
              > them is to couple the
              > abstraction (interface X) with the
              > implemention(class T). All the clients
              > using interface X now would be forced to change or
              > recompile if T is
              > changes, which these clients would not be interested
              > in T at all. But if you
              > really want to pay for this price, and are sure it
              > would not cause any
              > problems, then go for it.
              >
              > Other people may have better ideas. Hope this helps
              > you.
              >
              > Cheers,
              >
              > Ray
              >
              > -----Original Message-----
              > From: viswadeep veguru
              > [mailto:veguru_deep@...]
              > Sent: Sunday, August 03, 2003 2:01 AM
              > To: dpsg-nyc@yahoogroups.com
              > Subject: RE: [dpsg-nyc] A small problem...
              >
              >
              > Thanks
              > oleg shteynbuk, and Ray Ye for replying..
              >
              > Reflection could be a solution.
              > But i was searching for other way method.
              >
              > Let me again explaing u clearly.
              > I have a util class where i have Iterator of Objects
              > T.
              > restrict T such that it implements X. so i know what
              > all methods to invoke on T.
              > now i need to create a Object T and return.
              >
              > Small example is, finding average of an Iterator of
              > T
              > expect T implements X and X has both addition and
              > division operations defined. i should return average
              > in type T.
              >
              > I guess i could explain u more clearly.
              >
              > with regs
              > Viswa deep.
              >
              >
              >
              >
              > --- Ray Ye <rayye@...> wrote:
              > > Hi Viswadeep,
              > >
              > > I don't quite understand your problem yet. Now
              > that
              > > you can iterate through
              > > the list of objects whose type are "T", why could
              > > not you just return them
              > > as they are? If you don't know it is the type "T",
              > > how could you invoke
              > > methods on it (or how do you know which methods
              > you
              > > could invoke)?
              > >
              > > If your situation is you have object A whose type
              > is
              > > "R" and object B whose
              > > type is "S" in the list, where "R" and "S" are
              > > subtypes of "T", and the
              > > methods you want to invoke belong to "T", and you
              > > want to return a specific
              > > type of either "R" or "S", then it is a bit hard.
              > It
              > > depends on what
              > > languages you are using, if you are using C++, I
              > am
              > > not sure how you would
              > > do it. But if you are using Java, you can utilize
              > > the reflection API.
              > >
              > > Hope this helps,
              > >
              > > Cheers,
              > >
              > > Ray
              > >
              > > -----Original Message-----
              > > From: viswadeep veguru
              > > [mailto:veguru_deep@...]
              > > Sent: Friday, August 01, 2003 2:25 AM
              > > To: dpsg-nyc@yahoogroups.com
              > > Subject: [dpsg-nyc] A small problem...
              > >
              > >
              > > HI,
              > > Let me tell you what's my probelem context is.
              > > I need to write a code to iterate throw a set of
              > > objects and do some operations on them and return
              > > that
              > > Ovject.
              > > let that type be "T", now i need to get the
              > instance
              > > of "T" which is should be return type for my
              > method.
              > >
              > > How do I create a Object of type "T" which is not
              > > know
              > > to me till runtime...
              > > I can not say T t = new T()..
              > >
              > >
              > > What happens if i write an Small Inner class which
              > > extends "T" and will createa a clone of it self
              > and
              > > type cast to its parent.. and return a T
              > > Is that a good design....
              > >
              > >
              > > Please do give some pointer to solve this..
              > >
              > > with regs
              > > viswadeep veguru.
              > >
              > >
              > >
              > > __________________________________
              > > Do you Yahoo!?
              > > Yahoo! SiteBuilder - Free, easy-to-use web site
              > > design software
              > > http://sitebuilder.yahoo.com
              > >
              > >
              > > To Unsubscribe, send a blank message to:
              > > dpsg-nyc-unsubscribe@...
              > >
              > >
              > > Your use of Yahoo! Groups is subject to
              > > http://docs.yahoo.com/info/terms/
              > >
              > >
              >
              >
              > =====
              > with regs
              > viswa deep
              >
              > __________________________________
              > Do you Yahoo!?
              > Yahoo! SiteBuilder - Free, easy-to-use web site
              > design software
              > http://sitebuilder.yahoo.com
              >
              >
              > To Unsubscribe, send a blank message to:
              > dpsg-nyc-unsubscribe@...
              >
              >
              > Your use of Yahoo! Groups is subject to
              > http://docs.yahoo.com/info/terms/
              >
              >


              =====
              with regs
              viswa deep

              __________________________________
              Do you Yahoo!?
              Yahoo! SiteBuilder - Free, easy-to-use web site design software
              http://sitebuilder.yahoo.com
            • viswadeep veguru
              opps sorry i will contd.. This interface X should of type public interface X { public getInstance(); } Is that what ur talking about.. thanks
              Message 6 of 9 , Aug 6, 2003
                opps sorry i will contd..

                This interface X should of type
                public interface X {
                public <? extends X> getInstance();
                }

                Is that what ur talking about..
                thanks for inputs i will check and let u know..

                Thanks
                with regs
                Viswa deep





                --- viswadeep veguru <veguru_deep@...> wrote:
                > Thanks Ray Ye, for ur replay,
                > I guess i lost a point T in my context its a
                > Template
                > classe c++ , or I meen it any class that implements
                > X
                > thats what i mean, ur solution to generate a T
                > instance from X interface declaration.. is ok.
                > But i am writing code in java will i have change
                > even
                > if i use a generics. I don't think u can have
                > boundary
                > conditions in return type.
                > I meen if u have to declare such a method in side x
                > it should like this right
                > public interface X {
                >
                > }
                >
                > --- Ray Ye <rayye@...> wrote:
                > > Hi Viswa,
                > >
                > > If T implements X (which is an interface), and you
                > > really want to return T
                > > during the iteration(which I don't know the
                > reason,
                > > since X could have
                > > multiple implementations other than T), and you
                > are
                > > sure that your iterator
                > > only returns T and no other types of objects that
                > > implement X, and you
                > > refuse to use reflection, then in your interface
                > X,
                > > you could add a method
                > > to return an object of type T, and let you T
                > > implements X and return itself
                > > for this method.
                > >
                > > There are a lot of problems with this design. One
                > of
                > > them is to couple the
                > > abstraction (interface X) with the
                > > implemention(class T). All the clients
                > > using interface X now would be forced to change or
                > > recompile if T is
                > > changes, which these clients would not be
                > interested
                > > in T at all. But if you
                > > really want to pay for this price, and are sure it
                > > would not cause any
                > > problems, then go for it.
                > >
                > > Other people may have better ideas. Hope this
                > helps
                > > you.
                > >
                > > Cheers,
                > >
                > > Ray
                > >
                > > -----Original Message-----
                > > From: viswadeep veguru
                > > [mailto:veguru_deep@...]
                > > Sent: Sunday, August 03, 2003 2:01 AM
                > > To: dpsg-nyc@yahoogroups.com
                > > Subject: RE: [dpsg-nyc] A small problem...
                > >
                > >
                > > Thanks
                > > oleg shteynbuk, and Ray Ye for replying..
                > >
                > > Reflection could be a solution.
                > > But i was searching for other way method.
                > >
                > > Let me again explaing u clearly.
                > > I have a util class where i have Iterator of
                > Objects
                > > T.
                > > restrict T such that it implements X. so i know
                > what
                > > all methods to invoke on T.
                > > now i need to create a Object T and return.
                > >
                > > Small example is, finding average of an Iterator
                > of
                > > T
                > > expect T implements X and X has both addition and
                > > division operations defined. i should return
                > average
                > > in type T.
                > >
                > > I guess i could explain u more clearly.
                > >
                > > with regs
                > > Viswa deep.
                > >
                > >
                > >
                > >
                > > --- Ray Ye <rayye@...> wrote:
                > > > Hi Viswadeep,
                > > >
                > > > I don't quite understand your problem yet. Now
                > > that
                > > > you can iterate through
                > > > the list of objects whose type are "T", why
                > could
                > > > not you just return them
                > > > as they are? If you don't know it is the type
                > "T",
                > > > how could you invoke
                > > > methods on it (or how do you know which methods
                > > you
                > > > could invoke)?
                > > >
                > > > If your situation is you have object A whose
                > type
                > > is
                > > > "R" and object B whose
                > > > type is "S" in the list, where "R" and "S" are
                > > > subtypes of "T", and the
                > > > methods you want to invoke belong to "T", and
                > you
                > > > want to return a specific
                > > > type of either "R" or "S", then it is a bit
                > hard.
                > > It
                > > > depends on what
                > > > languages you are using, if you are using C++, I
                > > am
                > > > not sure how you would
                > > > do it. But if you are using Java, you can
                > utilize
                > > > the reflection API.
                > > >
                > > > Hope this helps,
                > > >
                > > > Cheers,
                > > >
                > > > Ray
                > > >
                > > > -----Original Message-----
                > > > From: viswadeep veguru
                > > > [mailto:veguru_deep@...]
                > > > Sent: Friday, August 01, 2003 2:25 AM
                > > > To: dpsg-nyc@yahoogroups.com
                > > > Subject: [dpsg-nyc] A small problem...
                > > >
                > > >
                > > > HI,
                > > > Let me tell you what's my probelem context is.
                > > > I need to write a code to iterate throw a set of
                > > > objects and do some operations on them and
                > return
                > > > that
                > > > Ovject.
                > > > let that type be "T", now i need to get the
                > > instance
                > > > of "T" which is should be return type for my
                > > method.
                > > >
                > > > How do I create a Object of type "T" which is
                > not
                > > > know
                > > > to me till runtime...
                > > > I can not say T t = new T()..
                > > >
                > > >
                > > > What happens if i write an Small Inner class
                > which
                > > > extends "T" and will createa a clone of it self
                > > and
                > > > type cast to its parent.. and return a T
                > > > Is that a good design....
                > > >
                > > >
                > > > Please do give some pointer to solve this..
                > > >
                > > > with regs
                > > > viswadeep veguru.
                > > >
                > > >
                > > >
                > > > __________________________________
                > > > Do you Yahoo!?
                > > > Yahoo! SiteBuilder - Free, easy-to-use web site
                > > > design software
                > > > http://sitebuilder.yahoo.com
                > > >
                > > >
                > > > To Unsubscribe, send a blank message to:
                > > > dpsg-nyc-unsubscribe@...
                > > >
                > > >
                > > > Your use of Yahoo! Groups is subject to
                > > > http://docs.yahoo.com/info/terms/
                > > >
                > > >
                > >
                > >
                > > =====
                > > with regs
                > > viswa deep
                > >
                > > __________________________________
                > > Do you Yahoo!?
                > > Yahoo! SiteBuilder - Free, easy-to-use web site
                > > design software
                > > http://sitebuilder.yahoo.com
                > >
                > >
                > > To Unsubscribe, send a blank message to:
                > > dpsg-nyc-unsubscribe@...
                > >
                > >
                > > Your use of Yahoo! Groups is subject to
                > > http://docs.yahoo.com/info/terms/
                > >
                > >
                >
                >
                > =====
                > with regs
                > viswa deep
                >
                > __________________________________
                > Do you Yahoo!?
                > Yahoo! SiteBuilder - Free, easy-to-use web site
                > design software
                > http://sitebuilder.yahoo.com
                >


                __________________________________
                Do you Yahoo!?
                Yahoo! SiteBuilder - Free, easy-to-use web site design software
                http://sitebuilder.yahoo.com
              • Michael J. Lee
                I m totally lost in what you are trying to accomplish here. Please provide a code to describe what you want to do. Anyway, I don t think this is any different
                Message 7 of 9 , Aug 6, 2003
                  I'm totally lost in what you are trying to accomplish here.

                  Please provide a code to describe what you want to do. Anyway, I don't think this is any
                  different from AbstractBuilder pattern. If you want to see how it works, look into
                  Java's implementation of 'JDBC' and 'XML'. Both uses the abstract factory to accomplish
                  to hide the implementation and programming by interface. [ I'm guessing that's what you
                  want to do ]

                  mj lee

                  --- viswadeep veguru <veguru_deep@...> wrote:
                  > opps sorry i will contd..
                  >
                  > This interface X should of type
                  > public interface X {
                  > public <? extends X> getInstance();
                  > }
                  >
                  > Is that what ur talking about..
                  > thanks for inputs i will check and let u know..
                  >
                  > Thanks
                  > with regs
                  > Viswa deep
                  >
                  >
                  >
                  >
                  >
                  > --- viswadeep veguru <veguru_deep@...> wrote:
                  > > Thanks Ray Ye, for ur replay,
                  > > I guess i lost a point T in my context its a
                  > > Template
                  > > classe c++ , or I meen it any class that implements
                  > > X
                  > > thats what i mean, ur solution to generate a T
                  > > instance from X interface declaration.. is ok.
                  > > But i am writing code in java will i have change
                  > > even
                  > > if i use a generics. I don't think u can have
                  > > boundary
                  > > conditions in return type.
                  > > I meen if u have to declare such a method in side x
                  > > it should like this right
                  > > public interface X {
                  > >
                  > > }
                  > >
                  > > --- Ray Ye <rayye@...> wrote:
                  > > > Hi Viswa,
                  > > >
                  > > > If T implements X (which is an interface), and you
                  > > > really want to return T
                  > > > during the iteration(which I don't know the
                  > > reason,
                  > > > since X could have
                  > > > multiple implementations other than T), and you
                  > > are
                  > > > sure that your iterator
                  > > > only returns T and no other types of objects that
                  > > > implement X, and you
                  > > > refuse to use reflection, then in your interface
                  > > X,
                  > > > you could add a method
                  > > > to return an object of type T, and let you T
                  > > > implements X and return itself
                  > > > for this method.
                  > > >
                  > > > There are a lot of problems with this design. One
                  > > of
                  > > > them is to couple the
                  > > > abstraction (interface X) with the
                  > > > implemention(class T). All the clients
                  > > > using interface X now would be forced to change or
                  > > > recompile if T is
                  > > > changes, which these clients would not be
                  > > interested
                  > > > in T at all. But if you
                  > > > really want to pay for this price, and are sure it
                  > > > would not cause any
                  > > > problems, then go for it.
                  > > >
                  > > > Other people may have better ideas. Hope this
                  > > helps
                  > > > you.
                  > > >
                  > > > Cheers,
                  > > >
                  > > > Ray
                  > > >
                  > > > -----Original Message-----
                  > > > From: viswadeep veguru
                  > > > [mailto:veguru_deep@...]
                  > > > Sent: Sunday, August 03, 2003 2:01 AM
                  > > > To: dpsg-nyc@yahoogroups.com
                  > > > Subject: RE: [dpsg-nyc] A small problem...
                  > > >
                  > > >
                  > > > Thanks
                  > > > oleg shteynbuk, and Ray Ye for replying..
                  > > >
                  > > > Reflection could be a solution.
                  > > > But i was searching for other way method.
                  > > >
                  > > > Let me again explaing u clearly.
                  > > > I have a util class where i have Iterator of
                  > > Objects
                  > > > T.
                  > > > restrict T such that it implements X. so i know
                  > > what
                  > > > all methods to invoke on T.
                  > > > now i need to create a Object T and return.
                  > > >
                  > > > Small example is, finding average of an Iterator
                  > > of
                  > > > T
                  > > > expect T implements X and X has both addition and
                  > > > division operations defined. i should return
                  > > average
                  > > > in type T.
                  > > >
                  > > > I guess i could explain u more clearly.
                  > > >
                  > > > with regs
                  > > > Viswa deep.
                  > > >
                  > > >
                  > > >
                  > > >
                  > > > --- Ray Ye <rayye@...> wrote:
                  > > > > Hi Viswadeep,
                  > > > >
                  > > > > I don't quite understand your problem yet. Now
                  > > > that
                  > > > > you can iterate through
                  > > > > the list of objects whose type are "T", why
                  > > could
                  > > > > not you just return them
                  > > > > as they are? If you don't know it is the type
                  > > "T",
                  > > > > how could you invoke
                  > > > > methods on it (or how do you know which methods
                  > > > you
                  > > > > could invoke)?
                  > > > >
                  > > > > If your situation is you have object A whose
                  > > type
                  > > > is
                  > > > > "R" and object B whose
                  > > > > type is "S" in the list, where "R" and "S" are
                  > > > > subtypes of "T", and the
                  > > > > methods you want to invoke belong to "T", and
                  > > you
                  > > > > want to return a specific
                  > > > > type of either "R" or "S", then it is a bit
                  > > hard.
                  > > > It
                  > > > > depends on what
                  > > > > languages you are using, if you are using C++, I
                  > > > am
                  > > > > not sure how you would
                  > > > > do it. But if you are using Java, you can
                  > > utilize
                  > > > > the reflection API.
                  > > > >
                  > > > > Hope this helps,
                  > > > >
                  > > > > Cheers,
                  > > > >
                  > > > > Ray
                  > > > >
                  > > > > -----Original Message-----
                  > > > > From: viswadeep veguru
                  > > > > [mailto:veguru_deep@...]
                  > > > > Sent: Friday, August 01, 2003 2:25 AM
                  > > > > To: dpsg-nyc@yahoogroups.com
                  > > > > Subject: [dpsg-nyc] A small problem...
                  > > > >
                  > > > >
                  > > > > HI,
                  > > > > Let me tell you what's my probelem context is.
                  > > > > I need to write a code to iterate throw a set of
                  > > > > objects and do some operations on them and
                  > > return
                  > > > > that
                  > > > > Ovject.
                  > > > > let that type be "T", now i need to get the
                  > > > instance
                  > > > > of "T" which is should be return type for my
                  > > > method.
                  > > > >
                  > > > > How do I create a Object of type "T" which is
                  > > not
                  > > > > know
                  > > > > to me till runtime...
                  > > > > I can not say T t = new T()..
                  > > > >
                  > > > >
                  > > > > What happens if i write an Small Inner class
                  > > which
                  > > > > extends "T" and will createa a clone of it self
                  > > > and
                  > > > > type cast to its parent.. and return a T
                  > > > > Is that a good design....
                  > > > >
                  > > > >
                  > > > > Please do give some pointer to solve this..
                  > > > >
                  > > > > with regs
                  > > > > viswadeep veguru.
                  > > > >
                  > > > >
                  >
                  === message truncated ===


                  __________________________________
                  Do you Yahoo!?
                  Yahoo! SiteBuilder - Free, easy-to-use web site design software
                  http://sitebuilder.yahoo.com
                • Ray Ye
                  If T could be any classes that implement X, then you could not call any specific methods on T, since you don t the type of class until runtime. So it looks
                  Message 8 of 9 , Aug 6, 2003
                    If T could be any classes that implement X, then you could not call any
                    specific methods on T, since you don't the type of class until runtime. So
                    it looks like you are really interested in X not T. Back to your original
                    question, now that you have a list of X (but remember this is really a list
                    of Ts that implement X), why would you want to return Ts? You already have
                    them!

                    Anyways, a code snippet may help us a bit here,
                    public interface X
                    {
                    public X getImpl();
                    public void foo();
                    }

                    public class T1 implements X
                    {
                    public T1() {}
                    public X getIml() {
                    return this;
                    }
                    public void foo() {}
                    }

                    public class T2 implements X
                    {
                    public T2() {}
                    public X getImpl() {
                    return this;
                    }
                    public void() foo{}
                    }
                    etc.

                    In your interface, you declare getImpl() and return the interface itself
                    (this is very important, it is the interface not the implementation class,
                    thus, all your implementation class can return themselves as the
                    implementation of this function)

                    Hope this will shed some lights to your puzzle.

                    Cheers,

                    Ray

                    -----Original Message-----
                    From: viswadeep veguru [mailto:veguru_deep@...]
                    Sent: Wednesday, August 06, 2003 6:58 AM
                    To: dpsg-nyc@yahoogroups.com
                    Subject: RE: [dpsg-nyc] A small problem... contd..


                    opps sorry i will contd..

                    This interface X should of type
                    public interface X {
                    public <? extends X> getInstance();
                    }

                    Is that what ur talking about..
                    thanks for inputs i will check and let u know..

                    Thanks
                    with regs
                    Viswa deep





                    --- viswadeep veguru <veguru_deep@...> wrote:
                    > Thanks Ray Ye, for ur replay,
                    > I guess i lost a point T in my context its a
                    > Template
                    > classe c++ , or I meen it any class that implements
                    > X
                    > thats what i mean, ur solution to generate a T
                    > instance from X interface declaration.. is ok.
                    > But i am writing code in java will i have change
                    > even
                    > if i use a generics. I don't think u can have
                    > boundary
                    > conditions in return type.
                    > I meen if u have to declare such a method in side x
                    > it should like this right
                    > public interface X {
                    >
                    > }
                    >
                    > --- Ray Ye <rayye@...> wrote:
                    > > Hi Viswa,
                    > >
                    > > If T implements X (which is an interface), and you
                    > > really want to return T
                    > > during the iteration(which I don't know the
                    > reason,
                    > > since X could have
                    > > multiple implementations other than T), and you
                    > are
                    > > sure that your iterator
                    > > only returns T and no other types of objects that
                    > > implement X, and you
                    > > refuse to use reflection, then in your interface
                    > X,
                    > > you could add a method
                    > > to return an object of type T, and let you T
                    > > implements X and return itself
                    > > for this method.
                    > >
                    > > There are a lot of problems with this design. One
                    > of
                    > > them is to couple the
                    > > abstraction (interface X) with the
                    > > implemention(class T). All the clients
                    > > using interface X now would be forced to change or
                    > > recompile if T is
                    > > changes, which these clients would not be
                    > interested
                    > > in T at all. But if you
                    > > really want to pay for this price, and are sure it
                    > > would not cause any
                    > > problems, then go for it.
                    > >
                    > > Other people may have better ideas. Hope this
                    > helps
                    > > you.
                    > >
                    > > Cheers,
                    > >
                    > > Ray
                    > >
                    > > -----Original Message-----
                    > > From: viswadeep veguru
                    > > [mailto:veguru_deep@...]
                    > > Sent: Sunday, August 03, 2003 2:01 AM
                    > > To: dpsg-nyc@yahoogroups.com
                    > > Subject: RE: [dpsg-nyc] A small problem...
                    > >
                    > >
                    > > Thanks
                    > > oleg shteynbuk, and Ray Ye for replying..
                    > >
                    > > Reflection could be a solution.
                    > > But i was searching for other way method.
                    > >
                    > > Let me again explaing u clearly.
                    > > I have a util class where i have Iterator of
                    > Objects
                    > > T.
                    > > restrict T such that it implements X. so i know
                    > what
                    > > all methods to invoke on T.
                    > > now i need to create a Object T and return.
                    > >
                    > > Small example is, finding average of an Iterator
                    > of
                    > > T
                    > > expect T implements X and X has both addition and
                    > > division operations defined. i should return
                    > average
                    > > in type T.
                    > >
                    > > I guess i could explain u more clearly.
                    > >
                    > > with regs
                    > > Viswa deep.
                    > >
                    > >
                    > >
                    > >
                    > > --- Ray Ye <rayye@...> wrote:
                    > > > Hi Viswadeep,
                    > > >
                    > > > I don't quite understand your problem yet. Now
                    > > that
                    > > > you can iterate through
                    > > > the list of objects whose type are "T", why
                    > could
                    > > > not you just return them
                    > > > as they are? If you don't know it is the type
                    > "T",
                    > > > how could you invoke
                    > > > methods on it (or how do you know which methods
                    > > you
                    > > > could invoke)?
                    > > >
                    > > > If your situation is you have object A whose
                    > type
                    > > is
                    > > > "R" and object B whose
                    > > > type is "S" in the list, where "R" and "S" are
                    > > > subtypes of "T", and the
                    > > > methods you want to invoke belong to "T", and
                    > you
                    > > > want to return a specific
                    > > > type of either "R" or "S", then it is a bit
                    > hard.
                    > > It
                    > > > depends on what
                    > > > languages you are using, if you are using C++, I
                    > > am
                    > > > not sure how you would
                    > > > do it. But if you are using Java, you can
                    > utilize
                    > > > the reflection API.
                    > > >
                    > > > Hope this helps,
                    > > >
                    > > > Cheers,
                    > > >
                    > > > Ray
                    > > >
                    > > > -----Original Message-----
                    > > > From: viswadeep veguru
                    > > > [mailto:veguru_deep@...]
                    > > > Sent: Friday, August 01, 2003 2:25 AM
                    > > > To: dpsg-nyc@yahoogroups.com
                    > > > Subject: [dpsg-nyc] A small problem...
                    > > >
                    > > >
                    > > > HI,
                    > > > Let me tell you what's my probelem context is.
                    > > > I need to write a code to iterate throw a set of
                    > > > objects and do some operations on them and
                    > return
                    > > > that
                    > > > Ovject.
                    > > > let that type be "T", now i need to get the
                    > > instance
                    > > > of "T" which is should be return type for my
                    > > method.
                    > > >
                    > > > How do I create a Object of type "T" which is
                    > not
                    > > > know
                    > > > to me till runtime...
                    > > > I can not say T t = new T()..
                    > > >
                    > > >
                    > > > What happens if i write an Small Inner class
                    > which
                    > > > extends "T" and will createa a clone of it self
                    > > and
                    > > > type cast to its parent.. and return a T
                    > > > Is that a good design....
                    > > >
                    > > >
                    > > > Please do give some pointer to solve this..
                    > > >
                    > > > with regs
                    > > > viswadeep veguru.
                    > > >
                    > > >
                    > > >
                    > > > __________________________________
                    > > > Do you Yahoo!?
                    > > > Yahoo! SiteBuilder - Free, easy-to-use web site
                    > > > design software
                    > > > http://sitebuilder.yahoo.com
                    > > >
                    > > >
                    > > > To Unsubscribe, send a blank message to:
                    > > > dpsg-nyc-unsubscribe@...
                    > > >
                    > > >
                    > > > Your use of Yahoo! Groups is subject to
                    > > > http://docs.yahoo.com/info/terms/
                    > > >
                    > > >
                    > >
                    > >
                    > > =====
                    > > with regs
                    > > viswa deep
                    > >
                    > > __________________________________
                    > > Do you Yahoo!?
                    > > Yahoo! SiteBuilder - Free, easy-to-use web site
                    > > design software
                    > > http://sitebuilder.yahoo.com
                    > >
                    > >
                    > > To Unsubscribe, send a blank message to:
                    > > dpsg-nyc-unsubscribe@...
                    > >
                    > >
                    > > Your use of Yahoo! Groups is subject to
                    > > http://docs.yahoo.com/info/terms/
                    > >
                    > >
                    >
                    >
                    > =====
                    > with regs
                    > viswa deep
                    >
                    > __________________________________
                    > Do you Yahoo!?
                    > Yahoo! SiteBuilder - Free, easy-to-use web site
                    > design software
                    > http://sitebuilder.yahoo.com
                    >


                    __________________________________
                    Do you Yahoo!?
                    Yahoo! SiteBuilder - Free, easy-to-use web site design software
                    http://sitebuilder.yahoo.com


                    To Unsubscribe, send a blank message to: dpsg-nyc-unsubscribe@...


                    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                  Your message has been successfully submitted and would be delivered to recipients shortly.