Создание новых объектов

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Создание новых объектов - Presentation Transcript

    1. Создание новых объектов: композиция, наследование, делегирование
    2. Композиция
      • template<class _Ty, class _Container = deque<_Ty> >
      • class stack
      • {
      • public:
      • size_type size() const reference top()
      • { // return last element of mutable stack
      • return (c.back());
      • }
      • const_reference top() const
      • { // return last element of nonmutable stack
      • return (c.back());
      • }
      • void push(const value_type& _Val)
      • { // insert element at end
      • c.push_back(_Val);
      • }
      • void pop()
      • { // erase last element
      • c.pop_back();
      • }
      • protected:
      • _Container c; // the underlying container
      • };
    3. Композиция
      • class Engine {
      • public void start() {}
      • public void rev() {}
      • public void stop() {}
      • }
      • class Wheel {
      • public void inflate(int psi) {}
      • }
      • class Window {
      • public void rollup() {}
      • public void rolldown() {}
      • }
      • class Door {
      • public Window window = new Window();
      • public void open() {}
      • public void close() {}
      • }
      • public class Car
      • {
      • public Engine engine = new Engine();
      • public Wheel[] wheel = new Wheel[4];
      • public Door left = new Door(),
      • p ublic Door right = new Door();
      • public Car()
      • {
      • for(int i = 0; i < 4; i++)
      • wheel[i] = new Wheel();
      • }
      • }
      • public static void main(String[] args)
      • {
      • Car car = new Car();
      • car.left.window.rollup();
      • car.wheel[0].inflate(72);
      • }
    4. Композиция
      • public class XOnlineListener : XListener
      • {
      • XParser m_Parser;
      • IReader m_Reader;
      • public XOnlineListener(string a_ListenerName, IReader a_Reader, XParser a_Parser) : base(a_ListenerName)
      • {
      • m_Parser = a_Parser;
      • m_Reader = a_Reader;
      • }
      • protected override void ListenerLoop()
      • {
      • List<XCallInformation> calls = new List<XCallInformation>();
      • foreach (XBillingString billingString in m_Reader.Read())
      • {
      • XCallInformation info = m_Parser.ParseAndProcess(billingString);
      • if (info == null)
      • {
      • continue;
      • }
      • calls.Add(info);
      • }
      • XBilling.RegisterCall(calls);
      • }
      • }
    5. Композиция
      • XListenerPool.Instance.AddListener(
      • new XOnlineListener(&quot;Unitel&quot;, new XComReader(&quot;Unitel&quot;, ConfigurationManager.AppSettings[&quot;UnitelPort&quot;]), new XUnitelParser()));
      • XListenerPool.Instance.AddListener(new XOnlineListener(&quot;DX&quot;, new XIncrementFileReader(&quot;DX&quot;, ConfigurationManager.AppSettings[&quot; D xFile&quot;]), new XDxParser()));
      • XListenerPool.Instance.AddListener(new XFileListener(&quot;Unitel Backup&quot;, &quot;UnitelBackup&quot;, new XBackupProcessor(&quot;Unitel&quot;, new XUnitelParser())));
      • XListenerPool.Instance.AddListener(new XFileListener(&quot;DX Backup&quot;, &quot;DXBackup&quot;, new XBackupProcessor(&quot;DX&quot;, new XDxParser())));
      • XListenerPool.Instance.AddListener(new XFileListener(&quot;IP&quot;, &quot;IP&quot;, new XIpProcessor()));
    6. Наследование
      • class A
      • {
      • public void DoSomething();
      • }
      • class B : A
      • {
      • }
      • A a = new A();
      • A a1 = new B();
      • B b = new B();
    7. Наследование
      • class A
      • {
      • public virtual void DoSomething();
      • }
      • class B : A
      • {
      • public override void DoSomething();
      • }
      • A a = new A();
      • A a1 = new B();
      • B b = new B();
      • a.DoSomething();
      • a1.DoSomething();
      • b.DoSomething();
    8. Наследование
      • Пример про велосипеды
    9. Особенности наследования
    10. Полиморфизм
    11. Виды наследования
      • 1. Расширение существующего класса
    12. 2. Наследование от интерфейса
      • public interface IReader
      • {
      • ICollection<XBillingString> Read();
      • void Start();
      • v oid Stop();
      • }
      • public class XComReader : IReader
      • {
      • SerialPort m_Port = null;
      • string m_PortName;
      • public XComReader(string a_PortName)
      • {
      • m_PortName = a_PortName;
      • }
      • #region IReader Members
      • public void Start() { … }
      • public void Stop() { … }
      • public ICollection<XBillingString> Read()
      • {
      • lock (m_Port)
      • {
      • if (!m_Port.IsOpen)
      • {
      • return new XBillingString[0];
      • }
      • return new XBillingString[] { new XBillingString(m_Port.ReadLine()) };
      • }
      • }
      • #endregion
      • }
    13. 3. Наследование от базового класса (абстрактного класса)
      • abstract public class XParser
      • {
      • protected XParser()
      • {
      • }
      • public string ParserName
      • {
      • get { return GetType().Name; }
      • }
      • public static XParser Create(string a_ParserName) { ... }
      • public XCallInformation ParseAndProcess(XBillingString a_BillingString)
      • {
      • a_BillingString.SetParser(this);
      • XCallInformation result = DoParse(a_BillingString);
      • if (result == null)
      • {
      • XBilling.RegisterError(a_BillingString);
      • }
      • return result;
      • }
      • public XCallInformation Parse(XBillingString a_BillingString)
      • {
      • a_BillingString.SetParser(this);
      • return DoParse(a_BillingString);
      • }
      • protected abstract XCallInformation DoParse(XBillingString a_BillingString);
      • }
      • public class XUnitelParser : XParser
      • {
      • public XUnitelParser() : base()
      • {
      • }
      • protected override XCallInformation DoParse(XBillingString a_BillingString)
      • {
      • Regex parser = new Regex(@&quot;^[ ]*-[0-9]+[ ]*(([0-9]+).([0-9]+)) ([0-9]*)[ ]*([0-9]+)[ ]*(([0-9]+).([0-9]+)) ([0-9]+).([0-9]+).([0-9]+) ([0-9]+):([0-9]+):([0-9]+) ([0-9]+)[ ]*$&quot;);
      • Match match = parser.Match(a_BillingString.BillingString.Trim());
      • if (!match.Success)
      • {
      • return null;
      • }
      • return new XCallInformation(
      • ParserName,
      • match.Groups[3].Value,
      • match.Groups[4].Value,
      • int.Parse(match.Groups[1].Value),
      • int.Parse(match.Groups[2].Value) - 600,
      • int.Parse(match.Groups[5].Value),
      • int.Parse(match.Groups[6].Value) - 600,
      • int.Parse(match.Groups[13].Value),
      • new DateTime(
      • 2000 + int.Parse(match.Groups[9].Value),
      • int.Parse(match.Groups[8].Value),
      • int.Parse(match.Groups[7].Value),
      • int.Parse(match.Groups[10].Value),
      • int.Parse(match.Groups[11].Value),
      • int.Parse(match.Groups[12].Value)),
      • a_BillingString
      • );
      • }
      • }
    14. 4. Создание иерархии наследования
    15. Делегирование
    16. Заключение

    + kichikkichik, 5 months ago

    custom

    182 views, 0 favs, 2 embeds more stats

    Лекция Михаила Гуренкова по more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 182
      • 150 on SlideShare
      • 32 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds
    • 25 views on http://oop.mainfo.ru
    • 7 views on http://www.oop.mainfo.ru

    more

    All embeds
    • 25 views on http://oop.mainfo.ru
    • 7 views on http://www.oop.mainfo.ru

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories