Object-oriented Analysis, Design & Programming


Published on

Published in: Software, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Object-oriented Analysis, Design & Programming

  1. 1. Object-oriented Analysis, Design & Programming Allan Spartacus Mangune
  2. 2. Delivery • Lectures – 2.5 hours • 2 case studies and exercises – 30 minutes each
  3. 3. Agenda Object-oriented Analysis Object-oriented Design Object-oriented Programming
  4. 4. Object-oriented Analysis Best done in iterative and incremental approach • Refine as you learn more about the system and implementation constraints Develop the models of the system based on functional requirements • Does factor implementation constraints of the system into the model Organize requirement items around objects that interact with one another • Requirement items are mapped to the real things of the system • Each item may be defined as object with data and behavior
  5. 5. Process Model the system of its intended use taking into account the description and behavior of each object • Emphasize on what the system does Define how objects interact with one another Commonly used process tools • Use case • Conceptual models (also referred to Domain Models)
  6. 6. Use Case Source: http://en.wikipedia.org/wiki/File:Use_case_restaurant _model.svg A sequence of related actions to accomplish a specific goal Each role in the system is represented as actor The actor can be a human or other systems • Identify the main task of each actor • Read • Write/Update • Notification of effects of action taken on internal and/or external system
  7. 7. Conceptual Models Abstract ideas in problem domain Describes the each object of the system, its behavior and how objects interact with one another • Attributes, behaviors and constraints Use this model to build the vocabulary of concepts and validate your understanding of problem domain with domain experts • Defer encapsulation details to the design phase Source: http://en.wikipedia.org/wiki/File:Domain_model.png
  8. 8. Object-oriented Design System planning process Solve specific problem Promotes correct program flow
  9. 9. Starting the Design Phase Can be started in parallel with analysis phase • Incremental approach is preferred Use the artifacts in analysis phase as inputs • Use case models • Conceptual models
  10. 10. Key Concepts of Object-oriented Design Objects and Classes Encapsulation and Information Hiding Inheritance Polymorphism Interface
  11. 11. Objects The most basic elements in object-oriented design An object represents a real entity with attributes and behaviors • Has a unique identity in the system Objects interactions • Interface is defined to describe all the actions an object must perform
  12. 12. Class Represents the blue-print of an object • An object that is created based on a class is called an instance of that class Contains attributes, data and behaviors that act on the data Defines the initial state of data May contain interface that defines how the class interact with the other parts of the system • For this purpose, an interface is a set of methods and properties exposed through public access modifier
  13. 13. Encapsulation and Information Hiding The internals of an object is hidden • Restricting access to its data Prevents external code from setting the data in invalid state Access to the data can be provided indirectly through public properties and methods Reduces complexity of the system
  14. 14. Inheritance When a class derives from another class • The class that inherits from a based class is called inheriting class or subclass Promotes code reuse • Base class inherits all of the base class operations, unless overridden Subclass may define its own implementation of any of the operations of the base class
  15. 15. Polymorphism Ability of the inheriting class to change one or more behaviors of its base class • This allows the derived class to share the functionality of the base class
  16. 16. Interface An abstract class that contains methods without implementations • Defines the rules for method signature and return type • Implementation is deferred to the class the implements the interface Enforces rules to one or more classes that implement the interface
  17. 17. Object-oriented Programming Classes and Objects Access Modifiers Member Fields and Properties Methods Inheritance Polymorphism Interface
  18. 18. Access Modifiers public • The type or member can be accessed by any other code in the same assembly or another assembly that references it. private • The type or member can only be accessed by code in the same class. protected • The type or member can only be accessed by code in the same class or in a derived class. internal • The type or member can be accessed by any code in the same assembly, but not from another assembly. protected internal • The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly Source: http://msdn.microsoft.com/en- us/library/dd460654.aspx#Interfaces
  19. 19. Classes and Objects A class describes the object An object in an instance of a class • An object is instantiated through the constructor of the class public class Customer { public Customer() {} public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Customer Add() { return …. } } Customer customer = new Customer()
  20. 20. Member Fields and Properties Local variables that must be private to the class • Holds the data of the class External access to the fields are usually provided through public Properties public class Customer { private int id; private string firstName; private string lastName; public int Id { get { return id; } set { id = value; } } public string FirstName { … } public string LastName { … } } Customer customer = new Customer() customer.FirstName = “Allan Spartacus”
  21. 21. Methods Defines the behaviors of the class May or may not return a type • void – no return type Can be overloaded • The signature of each method must be unique public class Customer { … public Customer Add () { … } public Customer Add(Customer customer){ … } public Customer Edit () { … } public bool Delete(int id) { … } private void ConcatName(){ … } } Customer customer = new Customer() customer.Add(); customer.ConcatName();
  22. 22. Inheritance Enables a new class to reuse, extend and change the behavior of a base class. • All classes written in C# implicitly inherits from System.Object class • A C# class can only inherit from a single base class public class Person { public int Id { get; set; } public string FirstName { get; set; } } public class Customer : Person { public string CompanyName { get; set; } } public class Employee : Person { public string EmployeeNumber { get; set; } } Employee employee = new Employee(); employee.Id = 1; employee.FirstName = “Allan Spartacus”; employee.EmployeeNumber = “GF4532”;
  23. 23. Sealed Class To prevent a class from inheriting from, define it as a sealed class public sealed class Vendor : Person { public string CompanyName { get; set; } } public class InternationaVendor : Vendor { }
  24. 24. Abstract Class When a class is intended as a base class that cannot be instantiated, define it as abstract class • Multiple derived classes can share the definition of an abstract class An abstract class can be used as interface by defining abstract methods • Abstract methods do not have implementation code • Implementation code is defined in the derived class public abstract class Manufacturer {} Manufacturer manufacturer = new Manufacturer() public abstract class Item { public abstract void Add(); } public class Product : Item { public override void Add() { …. } } public class Service : Item { public override void Add() { …. } }
  25. 25. Interface A collection of functionalities that can be implemented by a class or struct While a class is limited to inherit from a single base class, it can implement multiple interfaces A class that implements an interface must define methods that have similar signatures defined in the interface interface class IItem { void Add(); } public abstract class Product : IItem { public void Add() { …. } } public class Service : IItem { public void Add() { …. } }
  26. 26. References Object-oriented analysis -http://www.umsl.edu/~sauterv/analysis/488_f01_papers/wang.htm http://en.wikipedia.org/wiki/Use_cases Object-oriented design - http://en.wikipedia.org/wiki/Object-oriented_design Object - http://en.wikipedia.org/wiki/Object-oriented_programming Encapsulation and data hiding - http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Polymorphism - http://en.wikipedia.org/wiki/Object-oriented_programming Interface - http://en.wikipedia.org/wiki/Object-oriented_programming Inheritance - http://en.wikipedia.org/wiki/Object-oriented_programming
  27. 27. Copyright (C) 2014. Allan Spartacus Mangune This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. License URL: http://creativecommons.org/licenses/by-nc- sa/4.0/