Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic: An Object Oriented Approach 2 – Designing Software Systems.

Similar presentations


Presentation on theme: "Visual Basic: An Object Oriented Approach 2 – Designing Software Systems."— Presentation transcript:

1 Visual Basic: An Object Oriented Approach 2 – Designing Software Systems

2 Class and Object A Class is a template for an Object Develop a class – get many objects A Class defines how an object is encapsulated Some parts of an object are not accessible by a user of the object (Private) Other parts define the object’s interface with its user (Public) In general, object data is private, and the operations that are provided to work with it are public The attributes or properties of an object reflect its internal data, and are public operations for accessing it

3 Class/Object Diagrams We can depict a class by describing its interface We can depict an object by stating its class and showing its property values

4 Object Relationships There are a number of ways that objects can interact in a program Inheritance – a Class relationship Composition – a Class relationship Aggregation – a Class relationship Collaboration (message passing) – an Object relationship Class relationships are defined for the whole class Object relationships occur between specific objects, or instances of a class

5 Inheritance One class of objects can be created as a specialist version of another class e.g. a scientific calculator is a specialist type of calculator There are generally considered to be two types of inheritance Code inheritance – an existing class is reused as the basis for a new class Interface inheritance – a new class conforms to the same interface as an existing class Visual Basic only implements the latter The next version of Visual Basic will implement Code Inheritance Calculator Scientific Calculator

6 Composition An object can be made up of several other objects e.g. an message has a recipient address, a subject and a body A powerful tool for creating complex classes Top-down decomposition/bottom-up composition bodyrecipient address subject message

7 Aggregation An object can contain multiples of other objects e.g. a spreadsheet has a number of cells Aggregation is another form of composition Only difference is that multiplicity is provided for On the diagram, can use * for many objects, a specific number, or allowable range (e.g ) cell spreadsheet *

8 Collaboration (message passing) An object can invoke the services of another e.g. a document can send data to a printer A ‘message’ is how one object gets another to do something for it Message can include information to be passed to the serving object Message format also allows for information to be returned from the serving object :a document :System Printer :print (“Hello World”)

9 Classes Candidates for a class Are things that are named in the system description at the requirements stage Can not normally be defined as a simple value (e.g. colour, length, number of wheels) These are attributes, also known as Properties Will normally have certain behaviours, operations or actions associated with them Can support interactions with other things Are able to alter their state in response to messages

10 Designing Classes and Interactions Start by defining how a user will interact with a class or set of classes A Use-Case diagram shows this Indicates user and interactions with the system (possibly one class) as a whole

11 Define a class From the use-case diagram Identify class(es) required Decide on Properties of class Decide on Methods of class

12 Properties and Methods A Property of a class is some attribute that each object in the class has its own copy of can take on a number of possible values can be complex - a Property can be an object can be defined in such a way that it can be retrieved, or… changed, or… both…… in response to a message A Method is an operation that any object of class can perform can require extra information to do its job can return a result to the object that invoked it is able to alter the internal data of an object of the class

13 Messages A Message is a request to invoke a Method or access a Property of an object normally will come from another object can be in response to an event that has occurred – e.g. the user has clicked a mouse button A message describes the entire interaction the object that sent it the object that is to receive it information passed along with it (e.g. a new Property value) any result that it has (e.g. the result of a calculation performed by the receiving object)

14 Object Interactions The ATMMachine object sends these messages: Deposit – must include the amount to be deposited Withdraw – must include the amount to be withdrawn Balance – will return a result – the account balance The AnAccount object (a member of the Account class), is the recipient of the messages

15 Summary A Class is a template for one or more objects an object is an instance of class Classes and Objects relate to other classes or Objects in various ways Classes define (and Objects have) Properties Methods An interaction between objects is done by one object passing a message to another


Download ppt "Visual Basic: An Object Oriented Approach 2 – Designing Software Systems."

Similar presentations


Ads by Google