Computer Architecture -
The most popular languages have all been designed around the prevalent architecture, called the von Neumann architecture.
von Neumann architecture
-
Both data and program are stored in the same memory.
-
The processor is a unit separate from the memory.
-
Instructions and data must be piped, or transmitted, from memory to the processor.
-
Results of operations in the processor must be moved back to memory.
-
The von Neumann architecture causes the actual features of the imperative languages to be
-
variables , which model the memory cells.
-
assignment statements , which are based on the piping operation; store and load.
-
the iterative form of repetition , (the instructions in a von Neumann computer are stored in adjacent cells of memory.)
Programming Methodologies -
Software engineering:
-
the analysis of both the programming process and programming language design.
-
under intense study since 1970s.
-
An important reason for the research in software engineering was the shift in the major cost of computing from hardware to software.
(From 80% hardware, 20% software; To 20 % hardware, 80 % hardware)
-
The primary programming language deficiencies that were discovered in the 1970s were incompleteness of type checking, inadequacy of control statements, and lack of facilities for exception handling.
-
E.g. Process-oriented design and the extensive efforts in the area of concurrency that are taking place in the 1980s are bringing with them the need for complete language facilities for creating and controlling concurrent program units.
-
Another example is the Object-oriented design (OOD) .
Object-oriented (OO) approach -
It emphasizes data design, concentrating on the use of logical, or abstract, data types to solve problems.
-
For data abstraction to be used effectively in software system design, it should be supported by the languages used to write the system.
A Data base Application Example:
Button Dialog Box Scrollbar
User Interface Objects
ListBox Form Printer
Employee People Product
Application Objects
Directors Liabilities
Databases Tables
Database Objects
Fields Records
OO Terminology -
Class (noun)
-
A Class is a Type of entities which have common attributes and behaviour.
-
Examples: Employee, Printer, etc.
-
Object or Instance (noun)
-
An object is a particular entity which has attributes and behaviours as defined by a Class.
-
Examples: John, Peter, Printer-1, Printer-2, etc.
-
Attribute (noun or adj.)
-
An attribute is a property of an object or class.
-
Example: Employee::Name, Employee::HKID, Printer::ModelNumber, Printer::Weight, etc.
-
An attribute can itself be an object or class.
-
Examples: Employee::Product, etc.
-
Message, Event
-
Objects communicate with each other through message or event passing.
-
Examples: Print, Save, Load, etc.
-
Method
-
Methods are the functions defined by the class or object.
-
Some methods are used to handle events.
-
Examples: Print, Save, Load, etc.
-
Some methods are used to process information.
-
Examples: CalculateAsset, FormatPage, etc.
Employee FormatPage Form PrintPage Printer
-
Constructor VS Destructor
-
Constructor is a special method of a class which is executed once when the object is first instantiated (created). A good place to put initialisation and setup code for the object.
-
Destructor is a special method of a class which is executed once when the object is destroyed. A good place to release resources holding by the object.
OO methods -
The THREE OO programming methods: Inheritance, Encapsulation and Polymorphism.
Encapsulation
-
What?
-
It separate the interface from the implementation.
-
It provide a well-define public interface to the user while hiding all internal complexities from them.
-
Why? A well-designed interface can save the user from having to know the complexities of the implementation in order to use your class/object.
-
How? In OO terms, an interface composes of methods and attributes visible to the user of your class.
-
An Employee class:
-
Identity the methods of an Employee from the context of the user, e.g. SignIn, SingOut, etc.
-
Identity the attributes of an Employee from the context of the user, e.g. StaffID, Position, Department, Salary, etc.
Base Class
People (for class Employee)
is-a-kind-of Derive Class
(from class People)
Employee
is-a-kind-of is-a-kind-of
FullTime PartTime
Employee Employee
Inheritance
-
What?
Inheritance specifies the relations between classes having similar properties.
-
Why?
-
It improves software reuse, eases software maintenance and eases software integration.
-
OOD provides two class types, i.e. Base Class (Super-class) and Derive Class (Sub-class)
-
Class Inheritance.
-
A derive class inherits all methods and attributes of the base class.
-
A derive class conceptually forms an “is-a-kind-of ” relationship with the base class.
Polymorphism -
What?
A particular function (e.g. Area()) behaves differently according to the class that the object belongs to. This is true even the object is accessed indirectly through a reference of a base class type.
-
Why?
-
It simplifies programming by treating derive classes as base classes. (E.g. for pass-by-reference parameter passing in function calls.)
-
It simplifies maintenance by not having to know the exact identity of the objects, making the code more general and extensible when new derive classes are created.
Abstraction. Allows a designer to ignore details and remain focused on the big picture. Start with a general system outline and progressively add more detail. (top-down approach)
Object Relationships -
Is-a-kind-of relationship.
-
Represented in OOD as inheritance, a derive class is-a-kind-of base class.
-
E.g. Employee is-a-kind-of People, having all the methods and attributes of People.
-
Consists-of Relationship.
-
Occurs when an object is composed of other objects.
-
Represented in OOD as attributes of a class.
-
E.g. People consists-of a Name.
-
Uses Relationship.
-
An object (client) uses another object (server) to accomplish some task.
-
An object can be both a client and a server.
-
E.g. A Form object uses a Printer object to print the form.
-
Contains Relationship
-
Occurs when an object acts as containers for other objects.
-
The containment is dynamic and usually transient, objects can be added to or removed from the container object.
-
Represented in OOD as a container class.
-
E.g. Lists, Queues, Forms, etc.
Share with your friends: |