180 likes | 201 Views
Explore the evolution of software and the key elements of object-oriented programming, including object instantiation, the runtime environment, mapping to the real world, and the object lifecycle.
E N D
Agenda • Evolution of software • OO software elements • Object instantiation • Run-time environment • Mapping to real-world • Object lifecycle
Evolution of Software • Remember: form, function, style • data, logic, paradigm • state, behavior, style • state: collection of all data values (e.g., at this time) • Paradigms • monolithic • modular • functional => ADTs => OO => componentware??
OO Software Elements: Objects • real life view: • person, place, thing, concept, event • OO view: instantiation of a class • storage view: • area of storage allocated to hold both the data for this object and its superclasses (its “state”), including all hidden data, and references to executable code the object can invoke/call • multiple objects of same class share executable code and static variables
OO Software Elements: Classes • real life view: • template, factory, pattern, IRS tax form • OO view: • abstraction of a kind of object • definition of services (methods) that can be performed • storage view: • one copy of all static variables per class, plus the storage to hold one copy of all method code, plus some overhead • no storage for object/instance state
Local Object Instantiation • two storage areas: • local reference to object • local storage for object’s state and methods • “new” is normally used • allocates local memory • object storage is released when: • object is no longer in use and garbage collector runs • program exits
Temperature Class private double fahr_value; public Temperature(double temp) {fahr_value = temp;} 3C320 3C000 Temperature() code f_to_c() code 3C200 public static double f_to_c(double temp) {return 9/5*(temp-32.0);} getCelsius() code 3C300 32.0 public double getCelsius() {return f_to_c(fahr_value);} 3C000 3C200 3C300 Local Object Storage • Declaration: Temperature outside_temp; outside_temp (2AF0) (object reference is null) • Storage allocation: • outside_temp = new Temperature(32.0); 2AF0 3C320 3C328 3C32C 3C330
3C320 32.0 3C000 Temperature() code 3C340 3C000 f_to_c() code 3C200 getCelsius() code 3C300 3C200 3C300 212.0 3C000 3C200 3C300 Two Local Objects of Same Class Temperature outside_temp = new Temperature(32.0); Temperature water_temp = new Temperature(212.0); 2AF0 3C320 3C328 2AF4 3C32C 3C330 3C340 3C348 3C34C 3C350
3C320 32.0 3C000 Temperature() code 3C340 3C000 f_to_c() code 3C200 getCelsius() code 3C300 3C320 3C200 3C300 212.0 3C000 3C200 3C300 Shallow Object Copy Temperature outside_temp = new Temperature(32.0); Temperature water_temp = new Temperature(212.0); Temperature a_temp = outside_temp; 2AF0 3C320 3C328 2AF4 3C32C 2AF8 3C330 3C340 3C348 3C34C 3C350
Remote Object Instantiation • four storage areas: • local reference to object (actually, for “stub”/proxy) • local storage for proxy and parameters • remote storage for remote proxy, parameters and return value/exception info • remote storage for object’s state and methods • “new” is not used • remote proxy causes “new” for remote object • foundation for most of EA infrastructure
Run-Time Environment • loads/unloads classes • schedules threads • allocates storage • runs garbage collection • interfaces with operating system
Mapping to Real World • enabled by from exposed state to exposed interface • handling large problems: desirable characteristics • object-orientation’s part in solving problems
Desirable Characteristics:Modularity • isolates functionality • serves as unit of decomposition • can be assigned as a work item • allows for a standard interface • speeds time to market by aiding problem partitioning • helps with understandability • thus maintainability and extensibility
Desirable Characteristics:Encapsulation • simplifies interface • promotes consistency • controls access • allows underlying data representation to change • aids maintainability
Desirable Characteristics:Abstraction • allows easier identification of reusable parts • saves work effort by closer mapping to problem • improves reliability by supporting reuse • makes changes easier to propagate • central, inherited concepts • saves development time by inheriting capability
Desirable Characteristics:Reuse • saves time • allows for purchase vs. roll-your-own • allows reaping benefits of accumulated experience from reused entity
Object Orientation and the Real World • Classes are generalizations and abstractions of real-world objects and their behaviors • examples: business concepts (Order), people (User), service provider (DatabaseInterface) • Objects are unique and have an identity • examples: • order[451] (instance of Order) • SaleClerk[“Jane Doe”] (instance of User) • inventory_db (instance of DatabaseInterface)
Bean Object Activation Activities • creation • create bean object but defer assigning storage for state • passivation • disassociate bean object from its state and save the state • removes bean object from memory • activation • loads bean object into memory • restores state and associates with bean object • removal • remove bean object from memory