CIS-75 Home http://www.c-jump.com/CIS75/CIS75syllabus.htm
public class ValuesEncapsulated { private int privateValue; int friendlyValue; public int publicValue; }//class ValuesEncapsulated
public class UtilityClass { // only static methods // no data members // no non-static methods }//class UtilityClass
Java does not support templates...
...Java has
Java generics allow a type or method to operate on objects of various types
while providing compile-time type safety.
In C++,
template < generic parameters >
class ParameterizedClass
{
// ...code...
};//class ParameterizedClass
template < generic parameters >
class ParameterizedUtilityClass
{
// only static methods
// no data members
// no non-static methods
}//class ParameterizedUtilityClass
Cause/effect... because of... Temporal....... before, after , at the exact time... Association.... XYZ knows... Abstraction.... imposed by attributes and their values. Aggregation.... XYZ is part of ... ; ... consists of ... Composition.... XYZ is part of ... ; ... consists of ... Inheritance.... XYZ is kind of ... ; ... is a ...
Relationships provide a problem solving methodology, among other things:
Heuristics (trial and error experimentation), previous experience, knowledge of best practices, and a "rule of thumb" approach can help to find a solution. Design patterns also communicate the "best practice" idioms and solutions.
For example,
A is a logical/physical part of B.
A is logically/physically contained in B.
A has a knowledge/awareness of B with persistence beyond a single encounter.
A is a member of B.
A communicates with B (on a regular basis.)
A owns or manages B.
|
|
Both represent
part - whole,
element - collection,
component - container
type relationships.
In composition,
The component object can only be part of one container obect.
The parts and the whole have the same persistence in time (longevity.)
|
|
In UML,
multiplicity of aggregation and composition relationships can be specified,
(similar to association relationship.)
encapsulation of aggregation and composition relationships also can be specified,
(just as in the case of association relationship.)
|
|
|
|
Association, aggregation, and composition relationships in UML, Java, C++ can be:
public
protected
private
friend, C++ implementation technique.
Inheritance in UML and C++ can be as above (excluding friends in UML.)
Inheritance in Java is public.
Supported by all object-oriented languages.
Abstract method represents responsibility.
Non-abstract method implements capability.
Abstract method has to be...
...overridden in descendent classes...
...for each responsibility a corresponding capability has to be provided.
Constructors cannot be abstract.
Presence of a single abstract method makes a class abstract.
It is prohibited to create objects of abstract classes.
It is allowed to create variables of a reference or pointer to an abstract class type.
Abstract classes can have data members and non-abstract methods.
Abstract method and class in Java:
public abstract class Document { public abstract void print(); //... }//abstract class Document
class Document
{
public:
// pure virtual method:
virtual void print() = 0;
//...
};//class Document
The only members of an interface are abstract methods
(those with no data members, and with no non-abstract methods.)
Interface has to be extended through inheritance.
The descendent can be an interface, an abstract class, or a non-abstract class.
Interface in Java:
interface Container
{
public void put( Object obj );
public Object get();
}//interface Container
class Container { public: virtual void put( Object ob ) = 0; virtual Object get() = 0; }//class Container
Object sending the message (stimulus) does not have
to know the subclass of the recipient object.
The same message (stimulus) can be interpreted differently,
causing different behavior, depending on the class of the recipient.
Polymorphism is most useful if controlled through inheritance.