Interfaces to replace multiple inheritence

Howdy,
I have, conceptually, the following situation: I have a Ball abstract class. The Ball has several
concrete methods. It also has an abstract method getAppearance (that would somehow return how a
Ball is visualized). I have several "adjective" subclasses that I would like to build from it, for example:
SpikyBall, GlowingBall, ColorBall, etc. I would like these classes to be concrete.
Additionally, I would like to have a concrete class of any permutation of this list of adjectives, for example:
SpikyColorBall, GlowingColorBall, SpikyGlowingColorBall. I want to accomplish this
using as little code rewriting as possible, and, hopefully, none at all.
Using certain other single letter languages that I won't name here, I used Multiple Inheritence. A
SpikyColorBall would inherit from both SpikyBall and ColorBall, who both inherited from
Ball. I was told I could accomplish this in Java using interfaces instead of multiple inheritence, which
Java doesn't support. How is this accomplished? Could you give me (or forward me to) a good
example? Again, the power I'm looking for is multiple inheritence's code-reusability.
As a side note, why did Java choose to use interfaces instead of multiple inheritence?

Courtesy of yawmark...
composition_v_inheritance
Bruce Eckel, author of Thinking In Java, has this to say about composition vs. inheritance:
When deciding between inheritance and composition, ask if you need to upcast to the base type. If not, prefer composition (member objects) to inheritance. This can eliminate the perceived need for multiple base types. If you inherit, users will think they are supposed to upcast.
Choose composition first when creating new classes from existing classes. You should only used inheritance if it is required by your design. If you use inheritance where composition will work, your designs will become needlessly complicated.
Bill Venners: Composition versus Inheritance
Use inheritance (of implementation) only when the class satisfies the following criteria:
1) "Is a special kind of," not "is a role played by a";
2) Never needs to transmute to be an object in some other class;
3) Extends rather than overrides or nullifies superclass;
4) Does not subclass what is merely a utility class (useful functionality you'd like to reuse); and
5) Within PD: expresses special kinds of roles, transactions, or things.
-- from Java Design: Building Better Apps and Applets (2nd Edition), by Peter Coad and Mark Mayfield

Similar Messages

  • Is multiple inheritence is possible in sap?

    can any one help me?
    is multiple inheritence possible in sap ?
    and is one class can extend multiplre interfaces??

    Hi,
            Multiple inheritance as a concept is not allowed in ABAP Objects. But the effect and behaviour that you get by multiple inheritance is acheviable in ABAP objects with the help of interfaces. As follows.
    An interface can inlcude more than one interface, that is an interface can extend more than one interface. Now if you have say interface1, interface2 and interface3.
    interface4 can be declared to include all three other interfaces. And you class can include this interface4 in its interfaces tab.
    Due to this your class gets the behviour(methods) that is defined in all ther interfaces. You can assign an object of this class to a reference of any one of these four interfaces. So one object can react to method calls on four different interfaces which is what you want to achevie in multiple inheritance.
    Regards,
    Sesh

  • I acheived Multiple Inheritence in JAVA !!!!!!!!

    Hi,
    Im in ob_imit2_a2 group. I can use member variables and methods of two(or more) classes in another class without importing them just like Multiple Inheritence in C++.
    TECHNICAL COMMENTS REQUIRED
    See Below
    ///////// Outer.java
    public class Outer implements myInterface, myInterface2{
    public Outer() {
    System.out.println("outer class");
    public void check()
         inter2.test();
         inter.test();
    ////////// myInterface.java
    interface myInterface{
    class interclass{
         interclass()
              System.out.println("SS");
         public void test()
              System.out.println("TEST");
    public interclass inter=new interclass();
    //////////myInterface2.java
    interface myInterface2{
    class interclass2{
         interclass2()
              System.out.println("SS 2");
         public void test()
              System.out.println("TEST 2");
    public interclass2 inter2=new interclass2();
    //////////// Main.java
    public class Main {
    public static void main(String abc[]) {
    Outer o = new Outer();
         o.check();
    }

    Any and all variables declared in an interface are always implicitly public, static, and final; meaning that they are constants and NOT member variables. You can call these methods directly from the main method (a static scope) as well; meaning that they are not associated with any instance of the class Outer; i.e. they are NOT inherited.
    The difference between inheritance (extending) and realization (implementing) is that when extending you inherit everything from your parent class, and while implementing you are taking up a role and agree to fulfill all the responsibilities (methods) of that role.

  • Is there an example to use interface to replace if then else pattern in F#

    is there an example to use interface to replace if then else pattern in F#
    i want to make match pattern with only one rule to represent dynamic number of rules which is use 
    let rec fun1 m number fun2param =
        match m with
        | fun2param(a,b,number) -> ****rewrite terms ****
    let fun2param number =
        if number = 1 then
                 function.....
        elif number = 2 then
                function ....
    computing nightmare

    In general, you use a match
    let fun2param number =
    match number with
    | 1 -> function.....
    | 2 -> function ....
    in the same way as you would use a `switch` construct in 'C' in place of a repeated if/elif...elif/else
    Your request is somewhat vague, so I'm not sure whether you would benefit from wrapping that behind an active pattern.

  • How to replace multiple occurences of space in a string to a single space?

    How to replace multiple occurences of space in a string to a single space?

    Hi,
    try this code.
    data : string1(50) type c,
              flag(1) type c,
              dummy(50) type c,
              i type i,
              len type i.
    string1 = 'HI  READ    THIS'.
    len = strlen( string1 ).
    do len times.
    if string1+i(1) = ' '.
    flag = 'X'.
    else.
    if flag = 'X'.
    concatenate dummy string1+i(1) into dummy separated by space.
    clear flag.
    else.
    concatenate dummy string1+i(1) into dummy.
    endif.
    endif.
    i = i + 1.
    enddo.
    write : / string1.
    write : / dummy.

  • Replace multiple space characters with a single space

    Hi,
    Oracle 11g R2.
    Looking for a way to replace multiple space characters in a row with a single space. For example, the text "abc abc" should look like "abc abc". I tried toying with replace, but it only works for the case of 2 spaces. Need a solution for the cases where there could be 2 or more spaces.
    select replace(column1, chr(32)||chr(32), chr(32)) from tablea

    Hi,
    If you had to do this without regular expressions, you could use:
    SELECT  REPLACE ( REPLACE ( REPLACE (str, ' ', '~ ')
                     , ' ~'
              , '~ '
              )     AS new_str
    FROM    table_x;assuming there is some sub-string (I used '~' above) that never occurs right next to a space.
    However, unless you're uisng Oracle 9 (or earlier, which you're not doing) you don't have to do this without regular expressions. As you can see, the way Solomon showed is much simpler.

  • Replacing multiple spaces with a single space

    Hi friends,
    I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
    Here are the cases:
    1. ' a b c d efg h' should be changed to 'a b c d e f g h'
    2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
    3. 'a b c d e f g h' should not be changed
    4. 'abcdefgh' should not be changed
    Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
    Thanks in advance!

    Hi,
    964559 wrote:
    Hi friends,
    I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
    Here are the cases:
    1. ' a b c d efg h' should be changed to 'a b c d e f g h'One solution is to post your string on this site, and then copy it back again. (See below for a more serious solution .)
    This site is doing exactly what you want the function to do: it replaces multiple consecutive spaces with a single space. As a result, it's hard to see what you mean.
    To preserve spacing on this site, type these 6 characters
    \(small letters only, inside curly brackets) before and after each section where you want spacing preserved.
    2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
    3. 'a b c d e f g h' should not be changed
    4. 'abcdefgh' should not be changed
    Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
    Thanks in advance!Regular expressions make this easy:SELECT TRIM ( REGEXP_REPLACE ( str
    , ' +'
    ) AS compressed_str
    FROM table_x;
    You can use nested REPLACE calls to get the same results, but it's messy.
    Edited by: Frank Kulash on Feb 5, 2013 10:18 AM
    Added TRIM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to find and replace multiple cells at a time

    I am doing repetitive work re find text in numbers but then replace following cells with text. How can I find and replace multiple cells at a time?
    i.e. doing my own budget spreadsheet and coding all transactions with description and code

    Did you try the "Find/Replace" dialog box?:
    Then click the "Replace All" button in the bottom left.

  • Replace multiple spaces

    Hi dear experts,
    I need a function/procedure that replaces multiple spaces by one space.
    (This is because of an Application Express representation of strings in a report).
    (I have to replace ' ' by '_' in this post just because of the same phenomenon).
    Strings like "This___is_an_________example"
    should become " This_is_an__example".
    I need something like:
    create or replace function remove_multispaces(text_in in varchar2) return varchar2 is
    begin
    while instr(text_in,'__') >0 /* two blanks */
    loop
    execute immediate replace (text_in,'__','_'); /*replace 2 blanks by 1 */
    end loop;
    return (text_in);
    end remove_multispaces;
    But this is definitely not working.
    Thank you for your help,
    Hergen.

    SQL> ed
    Wrote file afiedt.buf
    1 create or replace function replace_multispaces(in_str varchar2) return varchar2 is
    2 out_str varchar2(100):=in_str;
    3 begin
    4 while(instr(out_str,'__')>0) loop
    5 out_str:=replace(out_str,'__','_');
    6 end loop;
    7 return(out_str);
    8 exception
    9 when others then
    10 dbms_output.put_line(sqlerrm);
    11* end;
    SQL> /
    Function created.
    SQL> select replace_multispaces('This___is_an_________example') from dual
    2 ;
    REPLACE_MULTISPACES('THIS___IS_AN_________EXAMPLE')
    This_is_an_example
    SQL>

  • Replacing multiple spaces with another character

    i need to replace multiple spaces with another char in a string
    my code is
    Dim text as String="a bit much             a little much" Dim arr As String() = text.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)Dim newtext As String = String.Join(" ", arr)            MsgBox(newtext)           
     it returns to "a bit much  a little much "
    But i want to replace only long spaces with "="  as  "a bit much =a little much"
    How can i do that?

    This version uses two spaces to split the string and then trims any additional single spaces. It returns "a bit much = a little much".
    Dim text As String = "a bit much a little much "
    Dim parts() As String = text.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
    Dim newText As String
    If parts.Length = 2 Then
    newText = parts(0).Trim & " = " & parts(1).Trim
    End If

  • Replace multiple characters to single character

    Hi friends,
    I would like to replace multiple characters in a string to a single character. The character may be a pipe (|) or a tilde (~).
    For example "|||asdf||123|xyz||" should be changed to "asdf|123|xyz".
    I use Oracle 11g2.
    Thanks in advance!

    Without regexp
    with testdata as (
        select '||asdf||||123|xyz|' str from dual union all
        select 'asdf|123|||||||xyz||||' from dual union all
        select '||||||asdf|||123||||||xyz||||||' from dual
    select
    trim (both '|' from
        replace (
            replace (
                replace (str,'|','|'||chr(0))
                ,chr(0)||'|'
            ,chr(0)
    ) str
    from testdata
    STR
    "asdf|123|xyz"
    "asdf|123|xyz"
    "asdf|123|xyz"
    with regexp
    with testdata as (
        select '||asdf||||123|xyz|' str from dual union all
        select 'asdf|123|||||||xyz||||' from dual union all
        select '||||||asdf|||123||||||xyz||||||' from dual
    select
    trim (both '|' from
        regexp_replace (
            str
            ,'\|+'
            ,'|'
    ) str
    from testdata
    STR
    "asdf|123|xyz"
    "asdf|123|xyz"
    "asdf|123|xyz"
    Message was edited by: chris227 regexp added

  • ANN: Tutorial on Replacing Multiple or Single Templates in DW on   Child Pages

    FYI: this article is available for free reprints, as long as
    guidelines are
    followed:
    http://www.petersonsales.net/tutorial1.php
    Replacing Old Website Templates in Dreamweaver
    One of the most difficult tasks for a web designer is
    updating legacy
    websites. Legacy websites are websites which have existed for
    many years.
    Often these sites have outdated code or are badly in need of
    an upgrade. For
    years, Dreamweaver has used templates to allow an entire site
    to be updated
    at once simply by making changes to a master page. But what
    do you do when
    the template itself was developed with outdated code and the
    site needs a
    complete design overhaul? How do you fix it without having to
    cut and paste
    the content from every existing page to a newly designed one?
    Part 1 - Overwriting a Single Template
    Part 2 - Replacing Multiple Templates with One
    ~~~~~~~~~~~~
    Jefferis Peterson, Pres.
    Web Design and Marketing
    http://www.PetersonSales.com

    What Ken has said also applied to
    <img src="/assets/images/Lights/lights_select.jpg" width="400" height="400" alt="Lighting Thumbnails" />
    which look for the JPG in http://davidcoshdesign.com/assets/images/Lights/lights_select.jpg rather than http://davidcoshdesign.com/nea/assets/images/Lights/lights_select.jpg
    Gramps

  • Implementation of multiple inheritence

    hi
    i am goutam.how can we implement multiple inheritence in java.and how two super classes can be inherited in one sub class

    keep it to one thread, please!

  • Multiple Inheritence/Const Compiler bug

    I'm encountering what appears to be a bug when mixing multiple inheritence & const/non-const methods. The compiler (WorkShop 6 Update 2) is accepting the following ill-formed code :
    class Base1 {
    int a; //If Base1 is empty, the problem doesn't appear.
    //A virtual function elicits the bug as well.
    class Base2 {
    public:
    void mutator() { //non-const method   
    class Derived : public Base1, public Base2 {
    class Foo {
    private:
    Derived my_derived;
    public:
    void f() const {
    my_derived.mutator();
    int main (int argc, char* argv[])
    Foo my_foo;
    my_foo.f();
    Note how f() in class Foo is const, yet attempts to call mutator(), a non-const method that my_derived gets via inheritence to Base2. This is ill formed and should, I believe, yield a compiler error. If the code is just subtly changed, the correct error will appear. For instance, if Base1 is empty, the appropriate error appears. Alternatively, if Base2 appears before Base1 in Derived's inheritence list, then the appropriate error appears.
    Is this a known problem? Is there a patch available? I'm very concerned that this bug is allowing const-incorrect code to be developed unknowingly, as it has in the project I'm involved in.
    Thanks in advance for giving this your attention!
    David Michael

    The bug report hasn't been filed yet. If you have contract with Sun, please follow the service channel to file the report. Otherwise, I can do it for you. Please provide:
    - O/S version
    - Architecture
    Please notice that if you don't have contract with sun, the bug might be in a low priority.
    - Rose

  • Replacing multiple new line characters

    how to replace multiple new line characters in a line.
    Suppose for example my line contains Example1#####Example2##Example3###Example4,
    then the output should be Example1#Example2#Example3#Example4.

    Hi Sid,
    You Can try this code
    DATA: ld_string TYPE string,
          ld_string1 TYPE string,
          ld_string2 TYPE string,
          ld_string3 TYPE string.
    ld_string = 'Example1#####Example2##Example3###Example4'.
    REPLACE ALL OCCURRENCES OF '######' in ld_string with '#'.
    REPLACE ALL OCCURRENCES OF '####' in ld_string with '#'.
    REPLACE ALL OCCURRENCES OF '###' in ld_string with '#'.
    REPLACE ALL OCCURRENCES OF '##' in ld_string with '#'.
    write:/1 ld_string.
    Regards
    Pavan

Maybe you are looking for

  • Uploading the document giving error in CV01n transaction

    Hi All,    I created one content repository in ECC 5.0, when i was created that time it was giving the error http 401..etc. I solved it by entering the Content server Administrator username and password. After creating the content repository, i am tr

  • Solution manager monitering activities

    Hi all, can anybody please help me out on solution manager daily,weekly and monthly activities. please............... thanx in advance. vinnu.

  • What is the default password for weblogic 11G for EPM 11.1.2

    HI All, Just need to know the default user name and password for weblogic 11G for EPM 11.1.2. At the time of installation I have kept the default user name epm_admin and a password... but its not accepting that user name and password. Any help on the

  • NEW to lightroom.NEED HELP

    I import photos from camera to catalog and format the card.now i want to copy all RAW files to CD or another SD.Where to find those photos inside my computer ?

  • Draftsight - CAD - installing in 64bits

    *Warning: bad english ahead One of the most missing part of my linux arch box is a good CAD software. Was happy to see this http://www.3ds.com/products/draftsight/ - raftsight/ . But for now there are no 64 version and I fail to install the AUR packa