What are the disadvantages of inheritance in object oriented programming?
597977
deoending on how well defined the language is, it could be a lot more difficult to program
399952
If you've never used an object-oriented language before, you need to understand the underlying concepts before beginning to write code. You need to know what an object is, what a class is, how objects and classes are related, and how objects communicate by using messages. The first few sections of this chapter describe the concepts behind object-oriented programming. The last section shows how these concepts translate into code. \nWhat Is an Object?\nAn object is a software bundle of related variables and methods. Software objects are often used to model real-world objects you find in everyday life. \nWhat Is a Message?\nSoftware objects interact and communicate with each other using messages. \nWhat Is a Class?\nA class is a blueprint or prototype that defines the variables and the methods common to all objects of a certain kind. \nWhat Is Inheritance?\nA class inherits state and behavior from its superclass. Inheritance provides a powerful and natural mechanism for organizing and structuring software programs. \nWhat Is an Interface?\nAn interface is a contract in the form of a collection of method and constant declarations. When a class implements an interface, it promises to implement all of the methods declared in that interface. \nHow Do These Concepts Translate into Code?\nThis section looks at a small applet, and shows you the code that creates objects, implements classes, sends messages, establishes a superclass, and implements an interface.
599192
In the object oriented world of thinking you have objects that are made of classes. These classes can be ordered through a special inheritance relationship into hierarchies of parent/child relationships. \n\nUpcasting means taking a reference to an object and changing\nits type to that of any of its parent classes. (for java, add to this list also all the interfaces that any of the parent classes may be implementing)\n\nFor example:\nclass A extends B{\n}\nclass B{\n}\nclass Program{\n\n    .......\n    B b = new B();\n    A a = (A) b; // this is upcasting!\n    .......\n}\n\nUpcasting in java is implicit. This means that you dont need\nthe preceding parenthesis with the upcasting type.\n    A a = b;\nwould have equally worked. This is because you are going from something specific (class B - child) to something more general (class A - parent) and the java compiler can infer this fact by its design.\n\nDowncasting is the opposite:\n    .......\n    A a = new B(); //here you have an object from class B\n                   //referenced to a variable of class A\n                   //Implicit upcasting happens here.\n\n    B b = (B) a; // this is downcasting.\n\nDowncasting must be explicit. If you try to downcast an\nobject to a type that cant be downcasted to, then the compiler will offer protection by giving you an error.\nOtherwise your program would have crashed at runtime.\n\nYou can test with the operator instanceOf whether a \ndowncast is safe.\nexample:\n   if (a instanceOf (B)) { \n        b = (B)a;\n   }\n\nThe problem with this is that it creates a dependency in that segment of code and the type B. If in the future you create sibling to B classes you will have to remember to change all the places where you are checking with "instanceOf" and this can be a try nightmare on a large system.\n\nSo, generally speaking, you want to create code that avoids downcasting. This is not always possible and not always a good idea as there are many cases where explicit downcasting is needed or at least is possible to use without problems. \nAgain generally speaking, you want to create designs that have parts that are as independent, decoupled, reusable, robust, modular, and change adaptive as possible. This is not easy because many of these forces lead you to contradictions. So its all about making choices.\n\nfor an easy visual guide to java have a look at an online tutorial that I have recently added to: http://www.thanassis.com/java/index.htm
606315
Preventing unauthorized access to some piece of information or functionality. \n\nThe key money-saving insight is to separate the volatile part of some chunk of software from the stable part. Encapsulation puts a firewall around the chunk, which prevents other chunks from accessing the volatile parts; other chunks can only access the stable parts. This prevents the other chunks from breaking if (when!) the volatile parts are changed. In context of OO software, a "chunk" is normally a class or a tight group of classes. \n\nThe "volatile parts" are the implementation details. If the chunk is a single class, the volatile part is normally encapsulated using the private and/or protected keywords. If the chunk is a tight group of classes, encapsulation can be used to deny access to entire classes in that group. Inheritance can also be used as a form of encapsulation. \n\nThe "stable parts" are the interfaces. A good interface provides a simplified view in the vocabulary of a user, and is designed from the outside-in (here a "user" means another developer, not the end-user who buys the completed application). If the chunk is a single class, the interface is simply the class's public member functions and friend functions. If the chunk is a tight group of classes, the interface can include several of the classes in the chunk. \n\nDesigning a clean interface and separating that interface from its implementation merely allows users to use the interface. But encapsulating (putting "in a capsule") the implementation forces users to use the interface.
1038492
Classic ASP is not, but ASP.NET uses object-oriented languages. (such as C#.NET and VB.NET)
837695
Before I offer an answer, I would like to make a couple of comments.\n\nFirst, seeing how you are using Java, I'm assuming this is an introductory programming course. One thing I HIGHLY recommend you do in the future is COMMENT, COMMENT, COMMENT! Get in the habit of doing it now. It didn't make a huge difference for this particular piece of code, but if you want others to help you debug your code, they need to be able to understand your code.\n\nSecond, I would like to make a remark about n2thepower's answer. I agree that Java will probably be dead a few years down the road, but the fact is that most languages will end up dying at some point or another. More than likely, the class teaches principles of object-oriented programming and not Java, per se. These you can take with you anywhere, no matter what particular programming language you end up using, but if you fail to master these fundamental underpinnings, good luck. The reason for Java's widespread use in beginning programming classes is its relative "friendliness" to budding programmers. (I've heard the analogy of C++ to Java as a scalpel to kiddy scissors.)\n\nAs for my answer, I could follow your code up until the last for loop. It seems to me that the upper bound for your loop should be i <= max (instead of max + 1), otherwise you end up one index beyond the last assigned value for your integer array a[].
1066843
I'm assuming you're asking from a Java point of view, so I'll answer along those lines.\n\nAn interface defines a set of methods clustered around common theme. It provides no implementation at all. When a class "implements" an interface, it must provide an implemenation for each method defined in the interface.\n\nAn abstraction (or abstract class) also defines a set of methods clustered around a common theme. The main different is that the abstract class may have implemenation provided behind some or all of the methods, although it does not need to.\n\nIn Java, a class must extend exactly [abstract] class. If not specified, then Object is defaulted as that extended class.\n\nA class may implement as many interfaces as it wishes.
86041
Well, huh.  \n\nOkay, let's say we're making a dog simulator with OOP.  So we might have various "objects" in the game in order to give structure to our program; in this case, "dog" could be a primary object.  But anything that exists in our program would also be an object -- street, fire hydrant, owner, leash, policeman, etc.\n\nOur dog object will have various properties, methods, and events.  Properties are things that describe the object (possibly uniquely), methods are things the object can actually do, and events are things that can happen to the object that it can respond to.  For example, "color" might be a property, "smell(something)" might be a method, and "owner picks up leash" an event.\n\nA constructor is simply the most basic method for any object that actually creates a new unique object.  In this case anytime we define a new dog object we will call the constructor for that object, in which we might set some default properties (ie set color = "black") and call some methods to establish the object within the program framework.  For example, we might use a constructor to register the new dog object in the list of possible "encounter" events that can happen to other dogs.\n\nObviously this is a very basic introduction. The best way to familiarize yourself with OOP is to design a few very very basic programs -- let's say a program that runs a mouse through a maze.  Imagine all the objects, all the properties for those objects, all the methods those objects will have to do, and all the events the objects will have to respond to, and write them all out.  \n\nThen program something yourself in your favorite programming language and find out all the things you forgot to include  :)
25915
According to Object Oriented Design, you really shouldn't expose class properties directly. The task you're trying to accomplish can be done by using accessors with no Set method, ie. in this way:\n\nnamespace abc\n{\npublic class AbcData\n{\nprivate const string str = "xyz";\n\npublic string AbcString\n{\n   get { return str; }\n}\n}\n\n}\n\nIn this way, you're hiding str, and exposing it using the Get Accessor method.
718773
An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface, as shown in the following example:\n\ninterface ISampleInterface\n{\n    void SampleMethod();\n}\n\nclass ImplementationClass : ISampleInterface\n{\n    // Explicit interface member implementation: \n    void ISampleInterface.SampleMethod()\n    {\n        // Method implementation.\n    }\n\n    static void Main()\n    {\n        // Declare an interface instance.\n        ISampleInterface obj = new ImplementationClass();\n\n        // Call the member.\n        obj.SampleMethod();\n    }\n}\nAn interface can inherit from one or more base interfaces.\n\nWhen a base type list contains a base class and interfaces, the base class must come first in the list.\n\nA class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.
116814
No, it doesn't improve the method's performance but only substracts a hidden argument from the list. \n'static' is a semantic construct, by which you mean that a certain method belongs to the class, or it doesn't need internal data to deal with.\n\nOn the other side, if you care about 'calling' performance (again, not the performance of the method itself) then consider not using virtual methods unless really necessary. That should decrease calling overhead (virtual calls go through a vtable) a tiny little bit, which makes sense for functions that are called inside loops or the like.
982994
I found that it was a handicap to learn C before C++, because they operate along different paradigms...\n\nC = functional\nC++ = object oriented\n\nThe reason that learning C first is a handicap, is that C++ compilers will let you write non-object-oriented code (eg C code) and you end up not learning, or getting the benefit of, object-oriented code :-)\n\nKnowing about pointers, structures and memory management is very useful :-)
1029394
Keeping them for future use is also a problem. \nFinding the right one to use out of the stack in a presentation is also cumbersome.
1015124
The result will be false if the AbstractObject is an abstract class!\n\nThe result will be true if AbstractObject is a concrete class
1140564
I am not sure i got ur question but i presume you are asking about C++ in general. It object oriented programming different form the structured programming style of C.Object oriented binds data to methods and provides a better level of abstraction...if this sounds geek...learn about Classes and objects...else send me a mail...aint bragging but i am pretty good in C++
872560
A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.\n\n///
1030688
The object oriented programming will give the impression very unnatural to a programmer with a lot of procedural programming experience. In Object Oriented programming Encapsulation is the first pace. Encapsulation is the procedure of covering up of data and functions into a single unit (called class). An encapsulated object is often called an abstract data type. In this article let us see about it in a detailed manner. \n\nThe need of encapsulation is to protect or prevent the code (data) from accidental corruption due to the silly little errors that we are all prone to make. In Object oriented programming data is treated as a critical element in the program development and data is packed closely to the functions that operate on it and protects it from accidental modification from outside functions. \n\nEncapsulation provides a way to protect data from accidental corruption. Rather than defining the data in the form of public, we can declare those fields as private. The Private data are manipulated indirectly by two ways. The first method is using a pair of conventional accessor and mutator methods. Another one method is using a named property. Whatever be the method our aim is to use the data with out any damage or change.\n\nusing system;\npublic class Department\n{\nprivate string departname;\n.......\n\n// Accessor.\npublic string GetDepartname()\n{\nreturn departname;\n}\n\n// Mutator.\npublic void SetDepartname( string a)\n{\ndepartname=a;\n}\n\n}\nLike the above way we can protect the private data from the outside world. Here we use two separate methods to assign and get the required data.\n\npublic static int Main(string[] args)\n{\nDepartment d = new Department();\nd.SetDepartname("ELECTRONICS");\nConsole.WriteLine("The Department is :"+d.GetDepartname());\nreturn 0;\n}\nIn the above example we can't access the private data departname from an object instance. We manipulate the data only using those two methods.\n\nProperties are a new language feature introduced with C#. Only a few languages support \nthis property. Properties in C# helps in protect a field in a class by reading and writing to it. The first method itself is good but Encapsulation can be accomplished much smoother with properties.\n\nusing system;\npublic class Department \n{\nprivate string departname;\npublic string Departname\n{\nget\n{\nreturn departname;\n}\nset \n{\ndepartname=value;\n}\n}\n}\npublic class Departmentmain\n{\npublic static int Main(string[] args)\n{\nDepartment d= new Department();\nd.departname="Communication";\nConsole.WriteLine("The Department is :{0}",d.Departname);\nreturn 0;\n} \n}\n\nFrom the above example we see the usage of Encapsulation by using properties. The property has two accessor get and set. The get accessor returns the value of the some property field. The set accessor sets the value of the some property field with the contents of "value”. Properties can be made read-only. This is accomplished by having only a get accessor in the property implementation.