< IB < Group 4 < Computer Science
Object-Oriented Programming Languages

Java

PHP

Python

C++

Object-oriented design is another way of looking at the design process, which views a program from the standpoint of data rather than tasks. Because the functionality associated with this design process is often incorporated into high-level programming languages, we need to understand this design process before looking at specific high-level languages.

Objects as a programming concept

D.1.1 Outline the general nature of an object

In general an object can be defined as a location in memory having a value. This could be a variable or data structure. Usually when talking about objects it refers to instances of a class which can be seen as a container for multiple variables, but a class can also contain functions of the program.

D.1.2 Distinguish between an object (definition, template, or class) and instantiation.

To use an object or class it is necessary to instantiate the object first (unless using a static class). Instantiating a class means creating a location in memory for the object. The values contained inside an object will be individual to each instance of the object. Each instance of the class will usually have the same functions but these will behave differently based on the individual values.

D.1.3 Construct Unified Modelling Language (UML) diagrams to represent object designs.

D.1.4 Interpret UML diagrams.

The above UML diagram is of the class "BankAccount", with two private variables "owner" of type String and "balance" of type Dollar, defaulting to value of 0. Two functions are part of the class, "Deposit" and "Withdraw", both which take a value of type Dollar as their parameter.

D.1.5 Describe the process of decomposition into several related objects.

Decomposition in computer science, also known as factoring, refers to the process by which a complex problem or system is broken down into parts that are easier to conceive, understand, program, and maintain. Object-oriented decomposition breaks a large system down into progressively smaller classes or objects that are responsible for some part of the problem domain.

D.1.6 Describe the relationships between objects for a given problem.

Objects can have three kinds of relationships:

  • the has-a relationship
  • the is-a relationship
  • the uses-a relationship

The has-a relationship means that one type of object contains another or is composed of another. Some examples are: a car has-an engine, a bicycle has-a wheel, and a coffee cup has coffee. The has-a relationship is modeled with composition, which is discussed in Chapter 6. The is-a relationship means that one type of object is a more specific version of a general type. Some examples are: a car is-a vehicle, a bicycle is-a vehicle, and a coffee cup is-a cup. The is-a relationship is modeled with inheritance, which is also discussed in Chapter 6. The uses-a relationship means that during some activity, one type of object uses another type of object. Some examples are: a car uses-a squeegee (during a window-washing activity), a bicycle uses-a pump (during a tire-pumping activity), and a coffee cup uses-a stirrer (during a stirring activity).

D.1.7 Outline the need to reduce dependencies between objects in a given problem.

  • It increases maintenance overheads
  • Maintenance overheads refer to the changes that need to be made to the entire system if you make a change to a component.

For example if you change, B, it affects how C, D and E works, implying that you have to spend time fixing them to work with the “new” B. 

D.1.8 Construct related objects for a given problem.

D.1.9 Explain the need for different data types to represent data items.

  • char: smallest addressable unit of the machine that can contain basic character set. It is an integer type. Actual type can be either signed or unsigned depending on the implementation.
  • int: basic signed integer type. At least in the [−32767,+32767] range, thus at least 16 bits in size.
  • float: single precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the IEEE 754 single-precision binary floating-point format.
  • string: holds sequences of unsigned 16-bit (2-byte) code points that range in value from 0 through 65535. Each code point, or character code, represents a single Unicode character. A string can contain from 0 to approximately two billion (2 ^ 31) Unicode characters.

D.1.10 Describe how data items can be passed to and from actions as parameters.

Object oriented programming, this is preferred:

  obj.InsertRecord("raed", "1987");

Features of OOP

D.2.1 Define the term encapsulation.

Encapsulation is a method of packing data and sometimes functions into one component. It is used to simplify the development process and making the code more efficient.

D.2.2 Define the term inheritance.

Inheritance is a concept where a child class inherits from a parent class. The child class has access to most of the components of the parent class while being able to add additional features. It can also overwrite some functionality of the child class.

D.2.3 Define the term polymorphism.

Polymorphism is a way of accessing multiple object of different types in the same way. To do this you make use of a polymorphic type that can be accessed in a way that also applies to all the other types of the objects. This is often used in combination with inheritance where multiple different child classes can be accessed as a parent class type and providing access to all features from the parent class or features that have been overloaded by the child class. Polymorphic child classes do not allow access to added features of the child class.

D.2.4 Explain the advantages of encapsulation.

Encapsulations allows for certain information to remain private. For example, a function wouldn't be allowed to access a user's balance without the correct authentication token. Encapsulation promotes maintenance, as code changes can be made independently. Increases usability by keeping data private and providing public well-defined service methods the role of the object becomes clear to other objects. Finally, encapsulation makes running unit tests possible.

D.2.5 Explain the advantages of inheritance.

The main advantage is polymorphism: if functionality is also used by the superclass, code doesn't need to be duplicated. The code can be easily reused. By use of inheritance, some data may be made private in subclasses as required. Also: Overriding, with inheritance, we will be able to override the methods of the base class so that meaningful implementation of the base class method can be designed in the derived class.

D.2.6 Explain the advantages of polymorphism.

  • Same interface could be used for creating methods with different implementations
  • Reduces the volume of work in terms of distinguishing and handling various objects
  • Supports building extensible systems
  • Complete implementation can be replaced by using same method signatures

D.2.7 Describe the advantages of libraries of objects.

Libraries of objects can be imported to avoid "reinventing the wheel". Many common tasks that applications perform (such as sorting) already have well-tested libraries written to perform them. With permission, another developer's code can be shipped along yours to save development time. This also reduces the testing surface, as well-tested libraries are unlikely to have bugs.

D.2.8 Describe the disadvantages of OOP.

Objected oriented programs tend to have a much larger filesize than other programs. This was especially important in earlier times, where storage was limited, or in embedded systems were storage is still very limited. Objected oriented programs tend to be slower than linear programs, as the computer needs to traverse different classes and understand the relationships between them. OO programming languages tend to have a steep learning curve. Finally, object oriented programs tend to take more effort to create, as they require careful planning and conceptualization.

D.2.9 Discuss the use of programming teams.

Teams are set up to accomplish larger tasks as a group Advantages of the use of teams:

  • More members means more ideas, including ideas that might not have come about without a team
  • The strengths of some can cover up the weaknesses of others
  • With more "manpower" to work on problems, larger problems and projects could be taken on

Disadvantages of the use of teams:

  • If not handled properly, the weaknesses of some members could undermine the group as a whole
  • Different styles of programming and working have to learn to coincide and work together
  • Communication among members becomes a priority for the team by necessity

D.2.10 Explain the advantages of modularity in program development.

  • If a single procedure is developed it can be reused multiple times without having to retype the code
  • Programs can be designed more easily and more effectively due to the divisions of the entire code into sectors because a small team deals with only a small part of the entire code
  • Modular programming allows many programmers to collaborate on the same application
  • Code is stored across multiple files; code is also short, simple and easier to understand
  • Scoping of variables can be easily controlled
  • When errors are localized to a subroutine or function, they can be easily identified

Program development

D.3.1 Define the terms: class, identifier, primitive, instance variable, parameter variable, local variable.

Class: A class is the blueprint from which individual objects are created.

Identifier: Identifiers are the name of variables, methods, classes, packages, and interfaces. They are a way of referring to specific things.

Primitive: A value that is predefined by the language and is named to a reserved keyword.

D.3.2 Define the terms: method, accessor, mutator, consutrctor, signature, return value.

Method: A method is a part of a program that executes java code. It is not to be confused with a constructor method.

Accessor: An accessor method is a method that is used to obtain information about an object and is also used in order to access the data in that object

Mutator: A mutator method is a method that is used to set a value of a private field that cannot be publicly accessed.

Constructor: A constructor method is a method that creates one instance of a class

Signature: Refers to the method name and the number and type of its parameters. Return types and thrown exceptions are not considered part of the signature

Return value: It is the value or data type that is returned after a program has been run

D.3.3 Define the terms private, protected, public, extends, static.

Private: most restrictive keyword; Can only be accessed within the declared class

Protected: When declared, can only be accessed by the subclasses in another package or any class within the member class

Public: Can be accessed from any other class

Extends: This Java keyword is used when you want a class or object to inherit from another class or object.

Static: This keyword signifies that a member variable, or method, can be accessed without requiring an instantiation of the class to which it belongs.

D.3.4 Describe the uses of the primitive data types and the reference class string.

In examination questions the primitive types will be limited to int, long, double, char and Boolean.

Primitive data types are most commonly used to store simple values. They are also used as the building blocks of the more complex abstract data types.

Although String is not a primitive data type, it is considered a ‘basic’ type as it is used to store simple values. 

D.3.5 Construct code to implement assessment statements D.3.1 - D.3.4.

D.3.6 Construct code examples related to selection statements.

IF / ELSE Boolean conditions, e.g. WHILE list.hasNext()

D.3.7 Construct code examples related to repetition statements.

FOR loops WHILE loops

D.3.8 Construct code examples related to static arrays.

  • reading from an array
  • moving data to/from the array
  • printing out selections from it… etc.

D.3.9 Discuss the features of modern programming languages that enable internationalisation.

  • specialized text enablement
  • sorting behavior
  • date and time formatting
  • keyboard layouts
  • UTF-8 encoding
  • Use of common character sets among many platforms and languages, like UNICODE
  • Platform independent high level languages (like Java) enable code to run on many platforms

D.3.10 }Discuss the ethical and moral obligations of programmers.

  • Adequate testing of products to prevent possibilities of commercial or other damage
  • Acknowledging the work of other programmers (to avoid plagiarism)
  • Open Source movement
  • Robotics and artificial intelligence
  • Adequate testing of products to prevent possibilities of commercial or other damage
  • Acknowledging the work of other programmers (to avoid plagiarism)
  • Open Source movement
  • Robotics and artificial intelligence

Advanced program development

D.4.1 Define the term recursion.

D.4.2 Describe the application of recursive algorithms.

D.4.3 Construct algorithms that use recursion.

D.4.4 Trace recursive algorithms.

D.4.5 Define the term object reference.

D.4.6 Construct algorithms that use reference mechanisms.

D.4.7 Identify the features of the abstract data type (ADT) list.

D.4.8 Describe the application of lists.

D.4.9 Construct algorithms using a static implementation of a list.

D.4.10 Construct list algorithms using object references.

D.4.11 Construct algorithms using the standard library collections included in JETS.

D.4.12 Trace algorithms using the implementation described in assessment statements D.4.9 - D.4.11.

D.4.13 Explain the advantages of using library collections.

D.4.14 Outline the features of ADT's stack, queue, and binary tree.

D.4.15 Explain the importance of style and naming conventions in code.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.