D.1, D.2, D.3, and D.4
Object
representation of a real world entity. describes that data that this entity has (properties/attributes) and actions that this entity can perform (methods)).
Unified Modeling Language (UML)
Provides a way to visualize the design of any software system and has evolved into the standard for modeling object-oriented programs. Modern extension of flow charts and can be though of as a superset of flowcharts.
UML Class Diagram
Depict the classes within an object-oriented program as well as their collaborations. Classes within an object-orientated program are connected in various ways with each other and UML class diagrams represent those connections.
Association
how classes are connected. Represented by a line connecting the two classes. Each association has two roles and each role has a direction. Each association also has a multiplicities.
Multiplicities
Placed at each end of an association line and indicate the number of objects of one class linked to one object of the other class.
What does “1” as a Multiplicity mean?
Exactly One
What does “0..1” as a Multiplicity mean?
zero or one
What does “*” as a Multiplicity mean?
Many
What does “0..*” as a Multiplicity mean?
Zero or Many
What does “1..*” as a Multiplicity mean?
One or many
Inheritance
is a or is like relationship. In UML diagrams inheritance is displayed with hollow arrows.
Decomposition
breaking up the problem into several related objects.
What are the four relationships that can be described in a UML class diagram
Association
Dependency
Aggregation
Inheritance
Association
The simplest relationship that can be present between two or more objects. It is represented with a solid line. One or two roles labels may be present to signify the type of association that takes place.
Dependency (“uses” relationship)
one object is dependent on one or more objects in order to function. The implementation of an object depends on one or more other objects. Represented with a dashed arrow, that goes from the object to the object that the first one depends on.
Inheritance (“is a” relationship)
Signifies that one object is a specialized form of another object. Represented by a hollow triangle with a line. The triangle points to the parent
Aggregation (“has a” relationship
One object belongs to another object and none other. A special kind of association between two objects. The two objects are not dependent on one another. It is represented by a hollow diamond from the parent class then a line.
Dependencies
When one object uses another object, the first object depends on the second since it cannot function without it. Whenever the first object needs to be used, the second object will be used as well. Dependencies are directional.
What are Coupled Classes?
Two classes which use one another. The degrees of the relationship between Coupled Classes is continuous not discrete.
Why are dependencies are bad?
They decrease reuse. Reuse is found in code where parts are reiterated or have a replicated structure; helpful in code readability.
Changes in one class will affect other classes which may increase errors in code.
Data Types
Allow programs to classify these data into different types.
Integers
Real numbers (float and double)
Boolean
Strings
Parameter
the name of the information that is used in a method, function, or procedure
Argument
the value that is passed into a method, function, or procedure
Encapsulation
the inclusion of both data and actions into a single component. Classes contain data and actions that are built-in such a way so that their structure is hidden and can only be accessed outside the class via specific methods.
Plays the protective wall that prevents data and actions from being accessed from outside a class.
Creates a ‘black box’ for an object, separating its behavior and implementation by restricting access to data and actions as necessary
Polymorphism
the ability to have many forms
Static Polymorphism
Understanding the method signatures and decide the method that needs to be invoked for a particular method call depending on the number and types of parameters passed
Dynamic Polymorphism
A subclass overrides actions of the superclass. It allows for subclasses to alter any parent class actions and make them specific to their needs.
Advantages of Encapsulation
Data in a class can be made read or write only
A class restricts the ways that its data and actions can be altered or called
A class can hide the way that data is stored
Easier to maintain as changes to data and actions in a class can take place without being apparent on the outside, as long as data and actions can still be accessed through the same way
Increase in usability
Advantages of Inheritance
Extensibility: all child classes inherit the actions and data of a parent class. Furthermore, child class may add new functionality, extending the parent’s actions and data, or even redefining them
Reusability: child classes that inherit the actions and data of a parent class will not need to be altered in the event that an inherited action or data needs to be upgraded. When parent class actions are upgraded, all child classes that inherit from the parent class will automatically use the new upgraded version of these actions. This fact reduces maintenance overheads as an action needs only to be changed once and all the dependent child classes will use it
Information hiding: the parent class determines what actions and data are available to the child classes
Overriding of Actions: child classes may override parent actions in order to implement meaningful actions for their needs. AS such, for a child class, inheriting from a parent class means that it can use whichever data and actions needed, as well as implement or improve on any parent actions.
Advantages of Polymorphism
Object actions can have the same name but different parameter lists and processes
Subclasses can have their own unique actions, as well as being able to override or improve on parent actions
Subclasses inherit all parent data and actions, without rewriting code, and can alter the actions that they deem necessary. This allows for code reusability
Polymorphism provides a high degree of decoupling since to an external program the implementation behind actions is hidden. A common interface exists for a family of objects that abstracts and hides the details of the implementation.
Libraries of Objects
Collections of classes that have already been written in code and can be used by a programmer while developing a program. The availability of libraries as well as their use simplifies the work that has to be put into a project since standard, tested, working code is available for various functions.
Advantages of Libraries
Saves development time - classes and their methods do not need to be rewritten
Promotes abstraction - reusable code exists that functions without knowledge of internal working
libraries contain error-free/ robust code - because it has been used and tested many times;
promotes efficiency/organization - as code will be shorter/easier to read/ develop
familiarity with libraries - allow for easier maintenance/ modification
Disadvantages of Object Oriented Programming
Good for large-scale projects, but not for small projects with few developers and modules.
Size: much larger than other programs
Effort: requires a greater level of planning before any code is written
Speed: typically run slower due to their size.
Use of Programming Teams
Modular nature of OOP means that objects can be assigned to a different coder to program, as long as any shared methods are known.
Advantages of Programming Teams
Larger projects can be taken since more developers can work on them
Compared to a solo developer, members of a team may bring various ideas to the table that would not have come about without member collaboration
the strengths of some team members may offset the weaknesses of other members
team members do not know the workings of the whole project, and can thus concentrate their time and energy in developing part of a project to a higher standard
Disadvantages of Programming Teams
There needs to be honest, well-mannered communication between team members. There needs to be a common “language” to enable collaboration
Weakness of some team members may end up undermining the group as a whole
Since team members will not be aware of the project as a whole and because members will be working on different aspects, decisions, and project planning takes longer compared to a single developer project
Modularity
related to the process of dividing a computer program into separate smaller sub-programs that can be implemented and tested on their own before combining them all together to build the final program. Makes the program more effective when there are logic boundaries between the sub-programs and there are very few dependencies with each other.
Advantages of Modularity
Subprograms can be reused in other applications
Less new code needs to be written for a program
Team support.
The code of a program is comprised of a short, simple, and easy to understand smaller subprograms that are easier to maintain and debug
The structure of a program is easier to understand
Subprograms works as “black boxes” that can be changed or updated without other team members needing to be involved
Speedier completion of the subprograms and as a result the whole program itself, compared to taking on the program as one large problem
Class
Defines the fields and methods for a group of similar objects. An object is an instance of a class
Identifier
A broad terms for the name of a variable or method.
Primitive (Data Type)
int, long, double, char, Boolean, byte, etc.
instance variable
the fields in a class. When an object is created of that class type, it has its own version of the fields
Parameter Variable
Information sent into a method from the calling program.
example: public int add(int x, int y)
Local Variable
A variable which exists only as long as the code to which it belongs exists. So if declared in a method which is no longer being run; the variable no longer exists/it is overwritten
Method
a program routine or behavior contained within an object designed to preform a particular task on the fields within an object
Accessor
A method that allows access to the fields within an object
Example: getName()
Mutator
A method that looks the values of the files in an object to be changed
Example: setName()
Constructor
the method that correctly initializes and sets up an object when it is created. This method has the same name as the class it belongs to and has no return data type
example: public person()
Signature
the method name and its parameter types
example: doSomething(String y)
Return Value
The value returned by a method to the calling program
Private
Variables, methods, fields, and constructors that can only be accessed within the declared class itself. Classes cannot be private. An object is able to encapsulate itself and hide its data from outside access
Protected
Variables, methods, fields and constructors declared protected in the super-class can only be accessed by the sub-classes
Public
variables, methods, fields and constructors declared public can be access from any other classE
xtends
this is used by a sub-class to say that it inherits the fields and methods from a super-class
Static
A static is a member of a class which isn’t associated with the instance of a class. It belongs to the class itself. AS such, you can access the static member without first creating a class instance
8 primitive Data types
Byte
Short
Int
Long
Float
Double
Char
Boolean
String
Byte
Minimum value: -128
Max Value: 127
It occupies 8 bits of memory
Typically used for saving memory in large arrays of small numbers
Short
Minimum Value : -32,768
Maximum Value: 32767
It occupies 16 bits of memory
Typically used for the same reasons as a byte, but for a wider range of number
Int
min value: -2³1
Max: 2³1 - 1
It occupies 32 bits of memory
Most commonly used as primitive Data type to represent integer numbers
Long
Minimum value -2^63
max Value: 2^63 - 1
It occupies 64 bits of memory
Primitive Data type to represent integer numbers when the range of the int data type is not sufficient
Float
1.4 ^-45 to 3.4³8
It occupies 32 bits of memory
Typically used for saving memory in large arrays of floating point numbers. Should not be used as a data type for numbers that need precision
Double
4.9^-324 to 1.7³08
It occupies 64 bits of memory
Most commonly used data type for the representation of decimal values. Should not be used as a data type for precise values such as currency
Char
Minimum Value: ‘\u000’ - 0
max Value: ‘\ufff’ -65535
It occupies 16 bits of memory
represents a Unicode character
Boolean
Can take only take one of two values: true or false
Typically used for conditions that may have one of two outcomes
String
It is not a primitive Data type but rather a reference class
Typically used to represent series of characters
Once it is created its value cannot change and it is thus immutable
Common Character Sets
Used among many platforms and languages, like Unicode. Unlike ASCII, Unicode has a larger number of characters so has letters and symbols from different alphabets/languages
Platform independent Languages
High Level Programming languages like java enable code to run on many different plateforms
Ethical/Moral Obligations
Adequate Testing: to prevent possibilities of commercial or other damage
Plagiarism: Acknowledge the work of other programmer to avoid being accused of plagiarism
Open Source Movement: increasing support for open-source software where you are given access to the code for free, allowing you to make changes/customization to meet exact needs.
Advantages of Objects
Objects can be easily passed around the program, and so are modular in nature
Allows for re-use for objects already created
Debugging ease; if a bicycle is broke you replace the bolt, not the whole bike. Similarly, you can replace and diagnose specific objects
Members/Attributes/Features
Objects have their own variables, constants and methods associated to it. These are broadly known as ‘Members’ or ‘Features’ or “Attributes of an Object'“
Expressions
A construct made up of variables, Operators and method invocations which evaluate to a value. Expressions are the core components of statements; and these statements may be grouped into ‘statement blocks’
Statements
Statements are like sentences, it is a complete unit of execution; each line in a program is a statement. Methods are defined by the statements within them, since these create their behavior. Statements specify a sequence of actions which should be performed when the method is invoked
Statement Blocks
Any sequence of statements can be grouped together to function as a single statement when expressed within braces - {}.
A statement block can be written inside another statement, this is known as ‘nesting’ they are used to define methods.
Control Flow Statement
Statements are executed sequentially on their own. However, Java has control statements which break the sequential flow of code, and allow repetitive execution of statements and conditional execution of statements
Case-Switch-Break/default
A switch statement can have any number of possible execution paths for int, char and byte data types.
Break
Terminates a loop when a value is found or statement block completeE
Return
Exits from the current method and returns to where the method was originally invoked. By specifying a value with return, the exit can be achieved whilst sending the value back.
Benefit of Decomposition
Decomposing a problem into several related objects and then decomposing those objects again into even simpler related objects allows for the reduction of the complexity of a problem and makes it easier to deal with.